©
本文檔使用 php中文網手册 發布
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
});
}));
put(key, value);
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.
参数 | 类型 | 详述 |
---|---|---|
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. |
get(key);
Retrieves named data stored in the Cache object.
参数 | 类型 | 详述 |
---|---|---|
key | string |
the key of the data to be retrieved |
* |
the value stored. |
remove(key);
Removes an entry from the Cache object.
参数 | 类型 | 详述 |
---|---|---|
key | string |
the key of the entry to be removed |
removeAll();
Clears the cache object of any entries.
destroy();
Destroys the Cache object entirely, removing it from the $cacheFactory set.
info();
Retrieve information regarding a particular Cache.
Object |
an object with the following properties:
|