Cache
Module | ejs |
Definition | class Cache |
Inheritance | Cache Object |
Stability | Prototype. |
Cache meta class to manage in-memory storage of key-value data.
The Cache class provides an abstraction over
various in-memory and disk-based caching cache backends.
Properties
Qualifiers | Property | Type | Description |
get | limits | Object | Resource limits for the server and for initial resource limits for requests. |
Inherited Properties
Cache Class Methods
Qualifiers | Method |
(No own class methods defined)
Inherited Methods
Cache Instance Methods
Inherited Methods
Method Detail
- Description
- Cache constructor.
- Parameters
adapter: String | Adapter for the cache cache. E.g. "local". The Local cache is the only currently supported cache backend. [default: null] |
options: Object | Adapter options. The common options are described below, other options are passed through to the relevant caching backend. [default: expression] |
- Options
lifespan | Default lifespan for key values in seconds. |
resolution | Time in milliseconds to check for expired expired keys. |
timeout | Timeout on cache I/O operations. |
trace | Trace I/O operations for debug. |
module | Module name containing the cache connector class. This is a bare module name without ".mod" or any leading path. If module is not present, a module name is derrived using "ejs.cache" + adapter. |
class | Class name containing the cache backend. If the class property is not present, the class is derived from the adapter name with "Cache" appended. The first letter of the adapter is converted to uppercase. For example, if the adapter was "mem", the class would be inferred to be "MemCache". H. |
- Description
- Destroy the cache.
- Description
- Set a new expire date for a key.
- Parameters
key: String | Key to modify. |
when: Date | Date at which to expire the data. Set to null to never expire. |
- Returns
- True if the key's expiry can be updated.
- 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. If the key does not exist, it is initialized to the amount value.
- Description
- Read a key.
- Parameters
key: String | Key value to read. |
options: Object | Read options. [default: null] |
- 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
- Read a key and return an object
This will read the data for a key and then deserialize. This assumes that writeObj was used to store the
key value.
- Parameters
key: String | Key value to read. |
options: Object | Read options. [default: null] |
- 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 an object. P.
- 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
- 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
- Description
- Write the key and associated value to the cache. The value is written according to the optional mode option.
- Parameters
key: String | Key to modify. |
value: String | String value to associate with the key. |
options: Object | Options values. [default: null] |
- Options
lifespan | Preservation time for the key in seconds. |
expire | When to expire the key. Takes precedence over lifetime. |
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. |
version | Unique version identifier to be used for a conditional write. The write will only be performed if the version id for the key has not changed. This implements an atomic compare and swap. See read. |
throw | Throw an exception rather than returning null if the version id has been updated for the key. |
- Returns
- The number of bytes written, returns null if the write failed due to an updated version identifier for the key.
- Description
- Write the key and associated object value to the cache. The object value is serialized using JSON notation and
written according to the optional mode option.
- Parameters
key: String | Key to modify. |
value: Object | Object to associate with the key. |
options: Object | Options values. [default: null] |
- Options
lifespan | Preservation time for the key in seconds. Set to zero for never expire. |
expire | When to expire the key. Takes precedence over lifetime. |
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. |
version | Unique version identifier to be used for a conditional write. The write will only be performed if the version id for the key has not changed. This implements an atomic compare and swap. See read. |
throw | Throw an exception rather than returning null if the version id has been updated for the key. |
- Returns
- The number of bytes written, returns null if the write failed due to an updated version identifier for the key. X.