A cache object used to store and retrieve data, primarily used by $http and the script directive to cache templates and other data.
angular.module('superCache') .factory('superCache', ['$cacheFactory', function($cacheFactory) { return $cacheFactory('super-cache'); }]);
Example test:
it('should behave like a cache', inject(function(superCache) { superCache.put('key', 'value'); superCache.put('another key', 'another value'); expect(superCache.info()).toEqual({ id: 'super-cache', size: 2 }); superCache.remove('another key'); expect(superCache.get('another key')).toBeUndefined(); superCache.removeAll(); expect(superCache.info()).toEqual({ id: 'super-cache', size: 0 }); }));
Inserts a named entry into the Cache object to be retrieved later, and incrementing the size of the cache if the key was not already present in the cache. If behaving like an LRU cache, it will also remove stale entries from the set.
It will not insert undefined values into the cache.
Param | Type | Details |
---|---|---|
key | string | the key under which the cached data is stored. |
value | * | the value to store alongside the key. If it is undefined, the key will not be stored. |
* |
the value stored. |
Retrieves named data stored in the Cache object.
Param | Type | Details |
---|---|---|
key | string | the key of the data to be retrieved |
* |
the value stored. |
Removes an entry from the Cache object.
Param | Type | Details |
---|---|---|
key | string | the key of the entry to be removed |
Clears the cache object of any entries.
Destroys the Cache object entirely, removing it from the $cacheFactory set.
Retrieve information regarding a particular Cache.
object |
an object with the following properties:
|
© 2010–2017 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://code.angularjs.org/1.5.11/docs/api/ng/type/$cacheFactory.Cache