Improve this doc  View Source

$cacheFactory.Cache

  1. - type in module ng

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
   });
 }));

Methods