new CacheImpl(cacheStorage, factory, Helper [, config])
Initializes the cache.
Parameters:
Name | Type | Argument | 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 |
<optional> |
{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); }
Members
-
_cache :Storage
-
Cache entry storage.
Type:
-
_enabled :boolean
-
Flag signalling whether the cache is currently enabled.
Type:
- boolean
-
_factory :CacheFactory
-
Type:
-
_Helper :vendor.$Helper
-
Tha IMA.js helper methods.
Type:
- vendor.$Helper
-
_ttl :number
-
Default cache entry time to live in milliseconds.
Type:
- number
Methods
-
_canSerializeValue(value)
-
Tests whether the provided value can be serialized into JSON.
Parameters:
Name Type Description value
* The value to test whether or not it can be serialized.
Returns:
true
if the provided value can be serialized into JSON,false
otherwise.- Type
- boolean
-
_clone(value)
-
Attempts to clone the provided value, if possible. Values that cannot be cloned (e.g. promises) will be simply returned.
Parameters:
Name Type Description value
* The value to clone.
Returns:
The created clone, or the provided value if the value cannot be cloned.
- Type
- *
-
clear()
-
-
delete()
-
-
deserialize()
-
-
disable()
-
-
enable()
-
-
get()
-
-
has()
-
-
serialize()
-
-
set()
-