LocalCache

Moduleejs
Definition class LocalCache
InheritanceLocalCache inherit Object
StabilityPrototype.

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

QualifiersPropertyTypeDescription
get limitsObjectResource limits for the server and for initial resource limits for requests.

LocalCache Class Methods

(No own class methods defined)

QualifiersMethod

LocalCache Instance Methods

QualifiersMethod
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
sharedCreate 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.
lifespanDefault lifespan for key values in seconds. Set to zero for a default unlimited timeout.
resolutionTime in milliseconds to check for expired expired keys.
memoryMaximum memory to use for keys and data.
traceTrace I/O operations for debug.

destroy(): Void
Description
Destroy the cache.

expire(key: String, expires: Date): Boolean
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.

inc(key: String, amount: Number = 1): Number
Description
Increment a key's value by a given amount. This operation is atomic.
Parameters
key: String Key value to read.
amount: Number Amount by which to increment the value. This amount can be negative to achieve a decrement. [default: 1]
Returns
The new key value.

read(key: String, options: Object = null): String
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.
Parameters
key: String Key value to read.
options: Object Read options. [default: null]
Options
versionIf 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.

remove(key: String): Boolean
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.

setLimits(limits: Object): Void
Description
Update the cache cache resource limits. The supplied limit fields are updated. See the limits property for limit field details.
Parameters
limits: Object Object hash of limit fields and values.
See Also
limits

write(key: String, value: String, options: Object = null): Number
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
expiresWhen to expire the key. Takes precedence over lifetime.
lifespanPreservation time for the key in seconds. If zero, the key will never expire.
modeMode 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.
throwThrow an exception rather than returning null if the version id has been updated for the key.
versionRequired 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.