LocalCache
Module | ejs |
Definition | class LocalCache |
Inheritance | LocalCache ![]() |
Stability | Prototype. |
Fast, non-scalable, non-durable, in-memory key/value cache class.
The cache is in-process and is not available to other processes on the same machine. Key/value data is not persisted. Use this cache if you require the fastest, non-scalable key/value cache alternative. There is one cache per Application. All uses of the LocalCache class connect to the one cache using one domain of keys.
Properties
Qualifiers | Property | Type | Description |
---|---|---|---|
get | limits | Object | Resource limits for the server and for initial resource limits for requests. |
LocalCache Class Methods
Qualifiers | Method |
---|
LocalCache Instance Methods
Qualifiers | Method |
---|---|
LocalCache(options: Object = null) | |
Create and connect to the local cache. | |
destroy(): Void | |
Destroy the cache. | |
expire(key: String, expires: Date): Boolean | |
Set a fixed expire date for a key. | |
inc(key: String, amount: Number = 1): Number | |
Increment a key's value by a given amount. | |
read(key: String, options: Object = null): String | |
Read a key. | |
remove(key: String): Boolean | |
Remove the key and associated value from the cache. | |
setLimits(limits: Object): Void | |
Update the cache cache resource limits. | |
write(key: String, value: String, options: Object = null): Number | |
Write the key and associated value to the cache. |
Method Detail
LocalCache(options: Object = null)
- Description
- Create and connect to the local cache. An application has only one cache regardless of how many LocalCache instances are created. All LocalCache instances connect to the same underlying cache. Multiple interpreters can use the local cache to reliably share information.
- Parameters
options: Object Configuration options. [default: null]
- Options
shared Create or connect to a single, shared cache. If multiple interpreters in a single process create shared LocalCache instances they will be able to share key/value data. lifespan Default lifespan for key values in seconds. Set to zero for a default unlimited timeout. resolution Time in milliseconds to check for expired expired keys. memory Maximum memory to use for keys and data. trace Trace I/O operations for debug.
destroy(): Void
- Description
- Destroy the cache.
- Description
- Set a fixed expire date for a key. After defining an expiry, the key's lifespan will not be renewed via access to the key.
- Parameters
key: String Key to modify. expires: Date Date at which to expire the data. Set expires to null to cause the key to never expire.
- Returns
- True if the key's expiry can be updated.
- Description
- Read a key. Read will return the keys value or null if the key is not present or expired. If options.version is set to true, then the call will return an object with "data" and "version" properties where version is the key's unique update version ID. Each time the key is updated, the version ID is automatically changed to a new value. Versions IDs can be used used for conditional (CAS) writes.
- Options
version If set to true, the read will return an object hash containing the data and a unique version identifier for the last update to this key. This version identifier can be specified to write to peform an atomic CAS (check and swap) operation.
- Returns
- Null if the key is not present. Otherwise return key data as a string or if the options parameter specified "version == true", return an object with the properties "data" for the key data and "version" for the CAS version identifier.
- Description
- Remove the key and associated value from the cache.
- Parameters
key: String Key value to remove. If key is null, then all keys are removed.
- Returns
- True if the key was removed.
- Description
- Write the key and associated value to the cache. The value is written according to the optional mode option. The key's expiry will be updated based on the defined lifespan from the current time.
- Parameters
key: String Key to modify. value: String String value to associate with the key. options: Object Options values. [default: null]
- Options
expires When to expire the key. Takes precedence over lifetime. lifespan Preservation time for the key in seconds. If zero, the key will never expire. mode Mode of writing: "set" is the default and means set a new value and create if required. "add" means set the value only if the key does not already exist. "append" means append to any existing value and create if required. "prepend" means prepend to any existing value and create if required. NOTE: only "set" is implemented. throw Throw an exception rather than returning null if the version id has been updated for the key. version Required key version for the write to succeed. A version can be obtained via the read call. If set to true, the read will return an object hash containing the data and a unique version identifier for the last update to this key. This version identifier can be specified to write to peform an atomic CAS (check and swap) operation.
- Returns
- The number of bytes written, returns null if the write failed due to an updated version identifier for the key.