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

Expired items sometimes only expire after double time. #152

Closed intellix closed 9 years ago

intellix commented 9 years ago

I've got an expiry of 15 minutes for an item and was debugging why it doesn't sometimes call onExpire. I created a test case within inspector to see what was going on and it seems removeExpired() checks for expiredItem.expires < now which should be <=.

var cache = angular.element(document.body).injector().get('DSCacheFactory')('test', {
    onExpire: function() {
        console.log('onExpire: ' + new Date);
    }
});
cache.put('abc', 123);
cache.setRecycleFreq(2000);
cache.setMaxAge(2000);
console.log('put: ' + new Date);

The above expires either 20 or 40 seconds later depending on if there was an extra millisecond during the check.