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

capacity does not work on often reload #179

Closed Delagen closed 8 years ago

Delagen commented 9 years ago

capacity setted to 10 cache.keys().length = 135

on every page reload it requests resource and put into cache this code does not work because $$lruHeap.size() equals to 1

 if ($$lruHeap.size() > this.$$capacity) {
                this.remove($$lruHeap.peek().key);
              }

so capacity does not remove old items if they does not expire

jmdobry commented 9 years ago

What does often reload mean?

Delagen commented 9 years ago

Page reload. So every time cache initialized again.

jmdobry commented 9 years ago

I need to see your entire cache configuration. Code examples please. Version please. Even better, a plunker that demonstrates the issue. Details!

Delagen commented 9 years ago

capacity:10 maxAge: week storageMode:localstorage

on every page load http get: request?random puts on the cache

so if i make 1000 loads it make 1000 entries in localstorage

jmdobry commented 9 years ago

Could you please fork this plunker and demonstrate the issue? http://plnkr.co/edit/RXWGpYqRAfKPS6R38MXs?p=preview

Delagen commented 9 years ago

Refresh result and see as keys count exceed capacity http://plnkr.co/edit/6zyAvLYTDeHJSbCvUllF?p=preview

jmdobry commented 9 years ago

Indeed it does.

jmdobry commented 9 years ago

Can you try 4.4.0 and see if it works better?

Delagen commented 9 years ago

You can try the same plunker. Result the same.