Permalink
Browse files

Merge pull request #21 from riophae/fix-cleanup

Fix cleanup
  • Loading branch information...
2 parents b942415 + 2d377fa commit 83787513bb4ee5be38f3e8d870a9cb71187ce09a @d0ugal d0ugal committed Feb 14, 2016
Showing with 13 additions and 5 deletions.
  1. +1 −1 locache.js
  2. +12 −4 tests/specs/expire.js
View
@@ -526,7 +526,7 @@
var length = this.storage.length();
var prefix = this.cachePrefix;
- for (var i = 0; i < length; i++) {
+ for (var i = length - 1; i >= 0; i--) {
var key = this.storage.key(i);
// If the key matches, remove the prefix to get the original key
// and then make use of the normal remove method that will clean
View
@@ -83,22 +83,28 @@ describe("Expire Calculations:", function () {
expireKey1 = this.cache.expirePrefix + key1,
key2 = "mykey2",
cacheKey2 = this.cache.cachePrefix + key2,
- expireKey2 = this.cache.expirePrefix + key2;
+ expireKey2 = this.cache.expirePrefix + key2,
+ key3 = "mykey3",
+ cacheKey3 = this.cache.cachePrefix + key3,
+ expireKey3 = this.cache.expirePrefix + key3;
// Bypass the normal setting mechanisims by manually calling the
// storage wrapper around localStorage.
this.store[cacheKey1] = "value1";
this.store[cacheKey2] = "value2";
+ this.store[cacheKey3] = "value3";
// set the first value to expire on a date in the past, and then
// second to expire in the future.
this.store[expireKey1] = this.past;
- this.store[expireKey2] = this.future;
+ this.store[expireKey2] = this.past;
+ this.store[expireKey3] = this.future;
// Both values should be stored in localStorage - by passing the
// normal get method to avoid the checks for validation
expect(this.store[cacheKey1]).toBe("value1");
expect(this.store[cacheKey2]).toBe("value2");
+ expect(this.store[cacheKey3]).toBe("value3");
// Perform a cleanup.
this.cache.cleanup();
@@ -107,7 +113,9 @@ describe("Expire Calculations:", function () {
// second should be as originally stored.
expect(this.store[cacheKey1]).toBe(undefined);
expect(this.cache.get(cacheKey1)).toBe(null);
- expect(this.store[cacheKey2]).toBe("value2");
+ expect(this.store[cacheKey2]).toBe(undefined);
+ expect(this.cache.get(cacheKey2)).toBe(null);
+ expect(this.store[cacheKey3]).toBe("value3");
});
@@ -158,4 +166,4 @@ describe("Expire Calculations:", function () {
});
-});
+});

0 comments on commit 8378751

Please sign in to comment.