angular-cache
angular-cache copied to clipboard
Override default $resource cache
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
Do you have a plnkr to reproduce ? Or can you show your $resource call/query to do that get ? Also what is msApiProvider.
This does not work.
A plunker to reproduce would be most helpful to debug this!
You may be trying to use the cache without having been instantiated yet. Or try putting "cache: CacheFactory.get ('defaultCache')" instead of "cache: true"