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

option to disable all caching #82

Closed leon closed 10 years ago

leon commented 10 years ago

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?

jmdobry commented 10 years ago

Ya, I think something like that would be useful.

jmdobry commented 10 years ago

How about adding the following to the API?

leon commented 10 years ago

@jmdobry Looks good!

jmdobry commented 10 years ago

@leon Here's what I decided:

Questions? Comments? Concerns?

leon commented 10 years ago

@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?

jmdobry commented 10 years ago

@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 commented 10 years ago

@leon https://github.com/jmdobry/angular-cache/releases/tag/2.3.0

leon commented 10 years ago

@jmdobry Awesome!