CacheFactory

CacheFactory

new CacheFactory()

A instance of CacheFactory holds multiple caches, and provides methods for manipulating all of the caches at once.

Source:
Example
import CacheFactory from 'cachefactory';

const cacheFactory = new CacheFactory();
const cache = cacheFactory.createCache('my-cache');

Methods

clearAll()

Calls Cache#removeAll on each Cache in this CacheFactory.

Source:
Example
cacheFactory.clearAll();

createCache(id, optionsopt) → {Cache}

Create a new Cache. If a cache with the same id had been created in a previous browser session, then it will attempt to load any data that had been saved previously.

Parameters:
Name Type Attributes Description
id string

A unique identifier for the new Cache.

options object <optional>

Configuration options. See Cache.

Source:
Returns:

The new Cache instance.

Type
Cache
Example
import CacheFactory from 'cachefactory';

const cacheFactory = new CacheFactory();
const options = {...};
const cache = cacheFactory.createCache('my-cache', options);

cache.put('foo', 'bar');
console.log(cache.get('foo')); // "bar"

destroy(id)

Calls Cache#destroy on the Cache in this CacheFactory that has the specified id.

Parameters:
Name Type Description
id string

TODO

Source:
Example
cacheFactory.destroy('my-cache');

destroyAll()

Calls Cache#destroy on each Cache in this CacheFactory.

Source:
Example
cacheFactory.destroyAll();

disableAll()

Calls Cache#disable on each Cache in this CacheFactory.

Source:
Example
cacheFactory.disableAll();

enableAll()

Calls Cache#enable on each Cache in this CacheFactory.

Source:
Example
cacheFactory.enableAll();

exists() → {boolean}

Returns whether the Cache with the specified id exists in this CacheFactory.

Source:
Returns:

Whether the Cache with the specified id exists in this CacheFactory.

Type
boolean
Example
const exists = cacheFactory.exists('my-cache');

get(id) → {Cache}

Returns a reference to the Cache in this CacheFactory that has the specified id.

Parameters:
Name Type Description
id string

The id of the Cache to retrieve.

Source:
Throws:

Throws a ReferenceError if the Cache does not exist.

Type
ReferenceError
Returns:

The Cache instance.

Type
Cache
Example
const cache = cacheFactory.get('my-cache');

info() → {object}

Returns information on this CacheFactory and its Cache instance.

Source:
Returns:

The detailed information.

Type
object
Example
const info = cacheFactory.info();
info.size; // 3
info.caches['my-cache']; // { size: 1234, ... }
info.caches['my-cache2']; // { size: 51, ... }
info.caches['my-cache3']; // { size: 43, ... }

keys() → {Array.<string>}

Returns an array of identifiers of the Cache instances in this CacheFactory.

Source:
Returns:

The Cache identifiers.

Type
Array.<string>
Example
const keys = cacheFactory.keys();

keySet() → {object}

Returns an object of key-value pairs representing the identifiers of the Cache instances in this CacheFactory.

Source:
Returns:

The Cache identifiers.

Type
object
Example
const keySet = cacheFactory.keySet();

removeExpiredFromAll() → {object}

Calls Cache#removeExpired on each Cache in this CacheFactory and returns the removed items, if any.

Source:
Returns:

The removed items, if any.

Type
object
Example
const expired = cacheFactory.removeExpiredFromAll();

touchAll()

Calls Cache#touch on each Cache in this CacheFactory.

Source:
Example
cacheFactory.touchAll();