jmdobry / angular-cache

angular-cache is a very useful replacement for the Angular 1 $cacheFactory.
http://jmdobry.github.io/angular-cache
MIT License
1.39k stars 156 forks source link

Override default $resource cache #246

Open artemgrygor opened 8 years ago

artemgrygor commented 8 years ago

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

yogeshgadge commented 8 years ago

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

Droppers commented 7 years ago

This does not work.

jmdobry commented 7 years ago

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

viniciusaugutis commented 6 years ago

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