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

$http Cache seems to be caching all requests. #159

Closed JoseInTheArena closed 9 years ago

JoseInTheArena commented 9 years ago

I'm setting up my cache like this:

DSCacheFactory("defaultCache", {
    storageMode: "localStorage",
    maxAge: 3600000, // time in milliseconds
    deleteOnExpire: "aggressive"
});

$http.defaults.cache = DSCacheFactory.get('defaultCache');

My expectation was that for $http requests where I set the cache property to true, the cache would be enabled. It seems like the opposite is true. All requests are cached except those where I set the cache property false. Could I get some clarification on this?

jmdobry commented 9 years ago

Sure, regardless of what it says in Angular's documentation, you can see in the source code for $http that if you set $http.defaults.cache and you don't explicitly set config.cache to false for a given request, it will cache the request.

Angular-cache has absolutely zero control over when $http decides to cache a request. You'll either want to open an issue with Angular to fix their documentation, or to fix the code to match the behavior described in the docs.