CacheImpl ⇐ Cache
Configurable generic implementation of the Cache interface.
Kind: global class
Extends: Cache
- CacheImpl ⇐
Cache
- new CacheImpl(cacheStorage, factory, Helper, [config])
- ._cache :
Storage
- ._factory :
CacheFactory
- ._Helper :
vendor.$Helper
- ._ttl :
number
- ._enabled :
boolean
- .clear()
- .has()
- .get()
- .set()
- .delete()
- .disable()
- .enable()
- .serialize()
- .deserialize()
- ._canSerializeValue(value) ⇒
boolean
- ._clone(value) ⇒
\*
new CacheImpl(cacheStorage, factory, Helper, [config])
Initializes the cache.
Param | Type | Default | Description |
---|---|---|---|
cacheStorage | Storage |
The cache entry storage to use. | |
factory | CacheFactory |
Which create new instance of cache entry. | |
Helper | vendor.$Helper |
The IMA.js helper methods. | |
[config] | Object |
{ttl: 30000, enabled: false} |
The cache configuration. |
Example
if (cache.has('model.articles')) {
return cache.get('model.articles');
} else {
let articles = getArticlesFromStorage();
// cache for an hour
cache.set('model.articles', articles, 60 * 60 * 1000);
}
cacheImpl._cache : Storage
Cache entry storage.
Kind: instance property of CacheImpl
cacheImpl._factory : CacheFactory
Kind: instance property of CacheImpl
cacheImpl._Helper : vendor.$Helper
Tha IMA.js helper methods.
Kind: instance property of CacheImpl
cacheImpl._ttl : number
Default cache entry time to live in milliseconds.
Kind: instance property of CacheImpl
cacheImpl._enabled : boolean
Flag signalling whether the cache is currently enabled.
Kind: instance property of CacheImpl
cacheImpl.clear()
Kind: instance method of CacheImpl
cacheImpl.has()
Kind: instance method of CacheImpl
cacheImpl.get()
Kind: instance method of CacheImpl
cacheImpl.set()
Kind: instance method of CacheImpl
cacheImpl.delete()
Kind: instance method of CacheImpl
cacheImpl.disable()
Kind: instance method of CacheImpl
cacheImpl.enable()
Kind: instance method of CacheImpl
cacheImpl.serialize()
Kind: instance method of CacheImpl
cacheImpl.deserialize()
Kind: instance method of CacheImpl
cacheImpl._canSerializeValue(value) ⇒ boolean
Tests whether the provided value can be serialized into JSON.
Kind: instance method of CacheImpl
Returns: boolean
- true
if the provided value can be serialized into JSON,
false
otherwise.
Param | Type | Description |
---|---|---|
value | \* |
The value to test whether or not it can be serialized. |
cacheImpl._clone(value) ⇒ \*
Attempts to clone the provided value, if possible. Values that cannot be cloned (e.g. promises) will be simply returned.
Kind: instance method of CacheImpl
Returns: \*
- The created clone, or the provided value if the value cannot be
cloned.
Param | Type | Description |
---|---|---|
value | \* |
The value to clone. |