Skip to content

Commit

Permalink
Stable Version 3.0.0-beta.3
Browse files Browse the repository at this point in the history
Fixed #106
  • Loading branch information
jmdobry committed Mar 3, 2014
1 parent f14a829 commit 56b2a48
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 13 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,8 @@
##### 3.0.0-beta.3 03 March 2014

###### Backwards compatible bug fixes
- Fixed duplicate keys when using localStorage #106

##### 3.0.0-beta.2 25 February 2014

###### Backwards compatible bug fixes
Expand Down
2 changes: 1 addition & 1 deletion README.md
@@ -1,7 +1,7 @@
## angular-cache
__A very useful replacement for Angular's $cacheFactory.__

__Version:__ 3.0.0-beta.1
__Version:__ 3.0.0-beta.3

Documentation for 3.x.x can be found at [angular-data.codetrain.io](http://angular-data.codetrain.io).

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Expand Up @@ -2,7 +2,7 @@
"author": "Jason Dobry",
"name": "angular-cache",
"description": "angular-cache is a very useful replacement for Angular's $cacheFactory.",
"version": "3.0.0-beta.2",
"version": "3.0.0-beta.3",
"homepage": "https://github.com/jmdobry/angular-cache",
"repository": {
"type": "git",
Expand Down
21 changes: 15 additions & 6 deletions dist/angular-cache.js
@@ -1,7 +1,7 @@
/**
* @author Jason Dobry <jason.dobry@gmail.com>
* @file angular-cache.js
* @version 3.0.0-beta.2 - Homepage <https://github.com/jmdobry/angular-cache>
* @version 3.0.0-beta.3 - Homepage <https://github.com/jmdobry/angular-cache>
* @copyright (c) 2013 Jason Dobry <http://www.pseudobry.com>
* @license MIT <https://github.com/jmdobry/angular-cache/blob/master/LICENSE>
*
Expand Down Expand Up @@ -1024,7 +1024,7 @@ module.exports = function put(key, value) {
key: key,
value: value,
created: now,
accessed: now,
accessed: now
};

item.expires = item.created + this.$$maxAge;
Expand All @@ -1050,7 +1050,16 @@ module.exports = function put(key, value) {
});
// Set item
this.$$storage.setItem(this.$$prefix + '.data.' + key, angular.toJson(item));
keys.push(key);
var exists = false;
for (var i = 0; i < keys.length; i++) {
if (keys[i] === key) {
exists = true;
break;
}
}
if (!exists) {
keys.push(key);
}
this.$$storage.setItem(this.$$prefix + '.keys', angular.toJson(keys));
} else {
// Remove existing
Expand Down Expand Up @@ -1654,7 +1663,7 @@ module.exports = function setRecycleFreq(recycleFreq) {
},{}],18:[function(require,module,exports){
var defaults = require('../defaults'),
DSCache = require('../DSCache'),
version = '3.0.0-beta.2';
version = '3.0.0-beta.3';

/**
* @doc function
Expand Down Expand Up @@ -2235,7 +2244,7 @@ module.exports = {
* @id angular-cache
* @name Overview
* @description
* __Version:__ 3.0.0-beta.2
* __Version:__ 3.0.0-beta.3
*
* ## Install
*
Expand All @@ -2255,7 +2264,7 @@ module.exports = {
* also consumable by Browserify and you should be able to `require('angular-cache')`. The `main` file is `src/index.js`.
*
* #### Manual download
* Download angular-cache.3.0.0-beta.2.js from the [Releases](https://github.com/jmdobry/angular-cache/releases)
* Download angular-cache.3.0.0-beta.3.js from the [Releases](https://github.com/jmdobry/angular-cache/releases)
* section of the angular-cache GitHub project.
*
* ## Load into Angular
Expand Down
4 changes: 2 additions & 2 deletions dist/angular-cache.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "angular-cache",
"description": "angular-cache is a very useful replacement for Angular's $cacheFactory.",
"version": "3.0.0-beta.2",
"version": "3.0.0-beta.3",
"homepage": "http://jmdobry.github.io/angular-cache",
"main": "src/index.js",
"repository": {
Expand Down
13 changes: 11 additions & 2 deletions src/DSCache/put.js
Expand Up @@ -49,7 +49,7 @@ module.exports = function put(key, value) {
key: key,
value: value,
created: now,
accessed: now,
accessed: now
};

item.expires = item.created + this.$$maxAge;
Expand All @@ -75,7 +75,16 @@ module.exports = function put(key, value) {
});
// Set item
this.$$storage.setItem(this.$$prefix + '.data.' + key, angular.toJson(item));
keys.push(key);
var exists = false;
for (var i = 0; i < keys.length; i++) {
if (keys[i] === key) {
exists = true;
break;
}
}
if (!exists) {
keys.push(key);
}
this.$$storage.setItem(this.$$prefix + '.keys', angular.toJson(keys));
} else {
// Remove existing
Expand Down
46 changes: 46 additions & 0 deletions test/unit/DSCache/index.keys.test.js
Expand Up @@ -5,8 +5,53 @@ describe('DSCache.keys()', function () {
var cache = TestDSCacheFactory('DSCache.keys.cache');

cache.put(itemKeys[0], itemKeys[0]);
assert.deepEqual(cache.keys(), [itemKeys[0]]);

cache.put(itemKeys[0], itemKeys[2]);
assert.deepEqual(cache.keys(), [itemKeys[0]]);
assert.deepEqual(cache.get(itemKeys[0]), itemKeys[2]);

cache.put(itemKeys[1], itemKeys[1]);
assert.deepEqual(cache.keys(), [itemKeys[0], itemKeys[1]]);

cache.put(itemKeys[2], itemKeys[2]);
assert.deepEqual(cache.keys(), [itemKeys[0], itemKeys[1], itemKeys[2]]);

var keys = cache.keys();

assert.equal(keys[0], itemKeys[0]);
assert.equal(keys[1], itemKeys[1]);
assert.equal(keys[2], itemKeys[2]);

cache.remove(itemKeys[0]);
cache.remove(itemKeys[1]);
cache.remove(itemKeys[2]);

keys = cache.keys();

assert.equal(keys.length, 0);
assert.deepEqual(keys, []);
});
it('should return the array of keys of all items in the cache when using localStorage.', function () {
var itemKeys = ['item1', 'item2', 'item3'];

var cache = TestDSCacheFactory('DSCache.keys.cache', {
storageMode: 'localStorage',
storageImpl: $window.localStorage
});

cache.put(itemKeys[0], itemKeys[0]);
assert.deepEqual(cache.keys(), [itemKeys[0]]);

cache.put(itemKeys[0], itemKeys[2]);
assert.deepEqual(cache.keys(), [itemKeys[0]]);
assert.deepEqual(cache.get(itemKeys[0]), itemKeys[2]);

cache.put(itemKeys[1], itemKeys[1]);
assert.deepEqual(cache.keys(), [itemKeys[0], itemKeys[1]]);

cache.put(itemKeys[2], itemKeys[2]);
assert.deepEqual(cache.keys(), [itemKeys[0], itemKeys[1], itemKeys[2]]);

var keys = cache.keys();

Expand All @@ -21,5 +66,6 @@ describe('DSCache.keys()', function () {
keys = cache.keys();

assert.equal(keys.length, 0);
assert.deepEqual(keys, []);
});
});

0 comments on commit 56b2a48

Please sign in to comment.