Closed leon closed 10 years ago
Ya, I think something like that would be useful.
How about adding the following to the API?
AngularCache#disable()
AngularCache#enable()
AngularCache#isEnabled()
@jmdobry Looks good!
@leon Here's what I decided:
options
object ($angularCacheFactory()
, AngularCache#setOptions()
, and $angularCacheFactoryProvider.setCacheDefaults()
) now accepts a disabled
field, which can be set to true
and defaults to false
.$angularCacheFactory.enableAll()
will enable any disabled caches.$angularCacheFactory.disableAll()
will disable all caches.AngularCache#get()
and AngularCache#put()
will both immediately return undefined
instead of performing their normal functions.Questions? Comments? Concerns?
@jmdobry
'use strict'
angular.module('app', ['jmdobry.angular-cache]).config(function ($angularCacheFactoryProvider) {
$angularCacheFactoryProvider.setCacheDefaults({
disabled: true
});
});
Have I understood it correctly that by setting the disabled to true it will bypass the whole cache and that all the calls will go through to the backend?
@leon That is correct.
'use strict';
angular.module('app', ['jmdobry.angular-cache']).config(function ($angularCacheFactoryProvider) {
$angularCacheFactoryProvider.setCacheDefaults({
disabled: true
});
}).run(function ($angularCacheFactory) {
var cache = $angularCacheFactory('cache');
cache.put('1234', 'item');
cache.get('1234'); // undefined
cache.setOptions({ disabled: false });
cache.put('1234', 'item');
cache.get('1234'); // 'item'
});
@jmdobry Awesome!
I've been using angular-cache for a while now and I'm really liking it!
Though sometimes I feel the need to disable it totally to debug the backend.
Could we add a option that can be set via .config() that totally disables the plugin. That way it would be easy to just change a boolean in the app config to run without caching.
What do you think?