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

LocalStorage not emptied on clearall/destroyall #184

Closed willyboy closed 9 years ago

willyboy commented 9 years ago

Cache data in local storage is not cleared when clear/destroy all calls are made.

jmdobry commented 9 years ago

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.

willyboy commented 9 years ago

http://stackoverflow.com/questions/30624026/angular-cache-doesnt-clear-local-storage-cache-when-using-dscachefactory-destro/30624027#30624027

Version is 3.2.5 so I haven't upgraded yet because I haven't been able to review if there are any breaking changes.

My storage code is:

if(!DSCacheFactory.get(this.source)){
        DSCacheFactory(this.source);
      }
      var cache = {cache:DSCacheFactory.get(this.source)};
    }
    var that = this;
    $http.get(this.source,cache)
}

I've also noticed that on first page load, DSCacheFactory.get(this.source) is empty even if it exists in localStorage but DSCacheFactory(this.source) loads the cache from storage. I guess I would expect DSCacheFactory.get(this.source) to check localStorage since in my config I have:

DSCacheFactoryProvider.setCacheDefaults({
    storageMode:"localStorage",
    maxAge: 604800000, //7 days
    deleteOnExpire: "passive" //don't scan for expired items
  });
jmdobry commented 9 years ago

plunker demonstrating that it works with 4.2.0: http://plnkr.co/edit/hamvsZ?p=preview

plunker demonstrating that it works with 3.2.5: http://plnkr.co/edit/NiOEes?p=preview

Open the Resources tab in chrome devtools and observe the storage in http://run.plnkr.co

willyboy commented 9 years ago

Does anything look inherently wrong in the code I pasted? If not, it could be related to Ionic. Besides the difference of using/not using http, I don't see a difference in the code yet yours clearly works.

jmdobry commented 9 years ago

I updated this plunker to more closely match the code in your example, and it still works. Seems like it's either an issue with ionic or the environment in which your app is running.

You could try 4.x. Here are the breaking changes moving from 3.x to 4.x.

willyboy commented 9 years ago

Awesome, thanks for the help! If I discover anything about an incompatibility between Ionic and angular-cache I'll post it here just as a reference.

jmdobry commented 9 years ago

Cool