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

Storage Medium #196

Closed sriramjothimani closed 9 years ago

sriramjothimani commented 9 years ago

I see the below behavior when I choose to have localStorage as the storage medium. I would like to double check, if that is what it is intended to be or am misinterpreting it.

So I create a cache as follows,

var cnCache = CacheFactory("CNCache",{ maxAge: 24 * 60 * 60 * 1000 ,deleteOnExpire: 'aggressive' ,storageMode: 'localStorage'
});

And set the following attribute in cache, cnCache.put("myAttr","myValue");

Once the attribute is set am able to find it from localStorage. All is well till now.

Now I refresh the page and try to get the CNCache from cache factory which does not exist. But the data (myAttr) is still in localStorage. So I have been pushed to recreate the cache with the same name and options, again once the page is refreshed.

Now everything is back in shape, we were able to get hold of the attributes from the localStorage which was set before the page refresh.

Am not clear where in, though we set storageMode as localstorage it will not retain the cache but just the localStorage. And to access it every time we need to recreate the cache with the same options.

Please clarify.

jmdobry commented 9 years ago

to access it every time we need to recreate the cache with the same options.

That right there is the truth of JavaScript in the browser. localStorage can only hold strings. The JavaScript objects and methods created when you run var cnCache = CacheFactory("CNCache",{...}); cannot be serialized to localStorage (and they are wiped from memory when you refresh), so every time your apps boots up, it needs to execute var cnCache = CacheFactory("CNCache",{...});, which will then be able to access any data that was previously saved to localStorage.


Closing because I’m not sure this is an issue, if you are convinced that this is really a bug, please feel free to re-open the issue and add more information:

Otherwise support is done via the mailing list.