angular-cache icon indicating copy to clipboard operation
angular-cache copied to clipboard

Override default $resource cache

Open artemgrygor opened this issue 9 years ago • 4 comments

Hi all,

I'm trying to use angular-cache as default one for $recourse. At app.run

$http.defaults.cache = CacheFactory('defaultCache', {
  maxAge: 15 * 60 * 1000, // Items added to this cache expire after 15 minutes
  cacheFlushInterval: 60 * 60 * 1000, // This cache will clear itself every hour
  deleteOnExpire: 'aggressive' // Items will be deleted from this cache when they expire
});

Api.js config file (it is registered before app.run):

msApiProvider.register('currency', [
  '/api/currencies',
  {},
  {
    query: {
      method: 'GET',
      params: {},
      isArray: true,
      cache: true
    }
  }
]);

However, when I try to get this keys array is empty

var cache = CacheFactory.get('defaultCache');
var keys = cache.keys();

Any ideas? Thanks

artemgrygor avatar Oct 13 '16 19:10 artemgrygor

Do you have a plnkr to reproduce ? Or can you show your $resource call/query to do that get ? Also what is msApiProvider.

yogeshgadge avatar Oct 18 '16 15:10 yogeshgadge

This does not work.

Droppers avatar Nov 25 '16 21:11 Droppers

A plunker to reproduce would be most helpful to debug this!

jmdobry avatar Dec 12 '16 03:12 jmdobry

You may be trying to use the cache without having been instantiated yet. Or try putting "cache: CacheFactory.get ('defaultCache')" instead of "cache: true"

viniciusaugutis avatar Jan 02 '18 20:01 viniciusaugutis