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.
|get||limits||Object||Resource limits for the server and for initial resource limits for requests.|
LocalCache Class Methods
LocalCache Instance Methods
|LocalCache(options: Object = null)|
|Create and connect to the local cache.|
|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.|
LocalCache(options: Object = null)
- 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.
options: Object Configuration options. [default: null]
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 the cache.
- 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.
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.
- True if the key's expiry can be updated.
- 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.
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.
- 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.
- Remove the key and associated value from the cache.
key: String Key value to remove. If key is null, then all keys are removed.
- True if the key was removed.
- 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.
key: String Key to modify. value: String String value to associate with the key. options: Object Options values. [default: null]
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.
- The number of bytes written, returns null if the write failed due to an updated version identifier for the key.