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

cache.put does not respect options parameter #193

Closed simpixelated closed 9 years ago

simpixelated commented 9 years ago

First of all, great work on this module @jmdobry! However I'm running into a possible bug: I'm not able to set maxAge, or any other options via the Cache#put method, as described in the readme and #157.

var cache = CacheFactory.createCache('test');
cache.put(0, 'data', { maxAge: 1001 });

This correctly inserts the item into the cache, but when I log cache.info(0).maxAge it's still set to the default. Here's a plunker showing the problem: (open the console to see that it logs the default maxAge) http://embed.plnkr.co/6kxQKh2VRVH9KgZcAQbe/

The plunker is with angular-cache 4.3.2 and Angular 1.4.3. I'm also able to reproduce it with Angular 1.3.13.

simpixelated commented 9 years ago

Looking at the source for CacheFactory, it looks like the options it respects are storeOnResolve and storeOnReject. Was there ever a version that took all of the config options?

jmdobry commented 9 years ago

Sorry, the readme is incorrect. You can't set maxAge for an individual item

Edit: The readme doesn't say that you can set maxAge via put. The only options for put that the readme mentions are storeOnReject and storeOnResolve.

simpixelated commented 9 years ago

Thanks for the quick response! Is this something that's fairly easy to add? Like if the code is just made aware of all options can they work on a per item basis? Or would that require significant refactoring? I'm assuming the latter since you don't support it currently.

jmdobry commented 9 years ago

It would take some work yes, and greatly increase the complexity of the code.

simpixelated commented 9 years ago

Alright, then I'll use separate caches to handle that. Thanks!