$cacheFactory

  1. service in module ng

Factory that constructs Cache objects and gives access to them.

var cache = $cacheFactory('cacheId');
expect($cacheFactory.get('cacheId')).toBe(cache);
expect($cacheFactory.get('noSuchCacheId')).not.toBeDefined();

cache.put("key", "value");
cache.put("another key", "another value");

// We've specified no options on creation
expect(cache.info()).toEqual({id: 'cacheId', size: 2});

Usage

$cacheFactory(cacheId, [options]);

Arguments

Param Type Details
cacheId string

Name or id of the newly created cache.

options
(optional)
object

Options object that specifies the cache behavior. Properties:

  • {number=} capacity â turns the cache into LRU cache.

Returns

object

Newly created cache object with the following set of methods:

  • {object} info() â Returns id, size, and options of cache.
  • {{*}} put({string} key, {*} value) â Puts a new key-value pair into the cache and returns it.
  • {{*}} get({string} key) â Returns cached value for key or undefined for cache miss.
  • {void} remove({string} key) â Removes a key-value pair from the cache.
  • {void} removeAll() â Removes all cached values.
  • {void} destroy() â Removes references to this cache from $cacheFactory.

Methods

  • info();

    Get information about all the caches that have been created

    Returns

    Object
    • key-value map of cacheId to the result of calling cache#info
  • get(cacheId);

    Get access to a cache object by the cacheId used when it was created.

    Parameters

    Param Type Details
    cacheId string

    Name or id of a cache to access.

    Returns

    object

    Cache object identified by the cacheId or undefined if no such cache.

doc_AngularJS
2016-03-29 16:10:08
Comments
Leave a Comment

Please login to continue.