Skip to content

Commit

Permalink
Stable Version 4.2.0.
Browse files Browse the repository at this point in the history
Fixes #174
  • Loading branch information
jmdobry committed Apr 27, 2015
1 parent 8d145d2 commit cbeb9eb
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 29 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
##### 4.2.0 27 April 2015

###### Backwards compatible bug fixes
- #174 - Cache not being fully emptied if using localStorage and multiple web pages

##### 4.1.0 30 March 2015

###### Backwards compatible API fixes
###### Backwards compatible API changes
- #169 - Official support for ngResource

##### 4.0.2 22 March 2015
Expand Down
7 changes: 4 additions & 3 deletions dist/angular-cache.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* angular-cache
* @version 4.1.0 - Homepage <http://jmdobry.github.io/angular-cache/>
* @version 4.2.0 - Homepage <http://jmdobry.github.io/angular-cache/>
* @author Jason Dobry <[email protected]>
* @copyright (c) 2013-2015 Jason Dobry
* @license MIT <https://github.com/jmdobry/angular-cache/blob/master/LICENSE>
Expand Down Expand Up @@ -93,7 +93,7 @@ return /******/ (function(modules) { // webpackBootstrap

var _keySet = function (collection) {
var keySet = {},
key;
key = undefined;
for (key in collection) {
if (collection.hasOwnProperty(key)) {
keySet[key] = key;
Expand Down Expand Up @@ -201,7 +201,7 @@ return /******/ (function(modules) { // webpackBootstrap
};

this.peek = function () {
return _this.heap[0];
return _this.heap.length ? _this.heap[0] : undefined;
};

this.pop = function () {
Expand Down Expand Up @@ -656,6 +656,7 @@ return /******/ (function(modules) { // webpackBootstrap
}
$$data = {};
}
$$promises = {};
},

removeExpired: function removeExpired() {
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 dist/angular-cache.min.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "angular-cache",
"description": "angular-cache is a very useful replacement for Angular's $cacheFactory.",
"version": "4.1.0",
"version": "4.2.0",
"homepage": "http://jmdobry.github.io/angular-cache/",
"main": "dist/angular-cache.js",
"repository": {
Expand Down
39 changes: 18 additions & 21 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let _stringifyNumber = number => {
};

let _keySet = collection => {
var keySet = {}, key;
let keySet = {}, key;
for (key in collection) {
if (collection.hasOwnProperty(key)) {
keySet[key] = key;
Expand Down Expand Up @@ -122,9 +122,7 @@ class BinaryHeap {
bubbleUp(this.heap, this.weightFunc, this.heap.length - 1);
};

this.peek = () => {
return this.heap[0];
};
this.peek = () => this.heap.length ? this.heap[0] : undefined;

this.pop = () => {
let front = this.heap[0];
Expand All @@ -137,8 +135,8 @@ class BinaryHeap {
};

this.remove = node => {
var length = this.heap.length;
for (let i = 0; i < length; i++) {
let length = this.heap.length;
for (var i = 0; i < length; i++) {
if (this.compareFunc(this.heap[i], node)) {
let removed = this.heap[i];
let end = this.heap.pop();
Expand All @@ -157,9 +155,7 @@ class BinaryHeap {
this.heap = [];
};

this.size = () => {
return this.heap.length;
};
this.size = () => this.heap.length;
}
}

Expand All @@ -171,7 +167,7 @@ class BinaryHeapProvider {

class CacheFactoryProvider {
constructor() {
var defaults = this.defaults = {
let defaults = this.defaults = {
capacity: Number.MAX_VALUE,
maxAge: Number.MAX_VALUE,
deleteOnExpire: 'none',
Expand Down Expand Up @@ -321,7 +317,7 @@ class CacheFactoryProvider {
if (key) {
let item;
if ($$storage) {
var itemJson = $$storage().getItem(`${this.$$prefix}.data.${key}`);
let itemJson = $$storage().getItem(`${this.$$prefix}.data.${key}`);

if (itemJson) {
item = angular.fromJson(itemJson);
Expand Down Expand Up @@ -385,7 +381,7 @@ class CacheFactoryProvider {
let kSet = {};

if (keysJson) {
var keys = angular.fromJson(keysJson);
let keys = angular.fromJson(keysJson);

for (var i = 0; i < keys.length; i++) {
kSet[keys[i]] = keys[i];
Expand Down Expand Up @@ -431,8 +427,8 @@ class CacheFactoryProvider {
throw new Error('key must be a string!');
}

var now = new Date().getTime();
var item = {
let now = new Date().getTime();
let item = {
key: key,
value: _isPromiseLike(value) ? value.then(getHandler(storeOnResolve, false), getHandler(storeOnReject, true)) : value,
created: now,
Expand All @@ -446,9 +442,9 @@ class CacheFactoryProvider {
$$promises[key] = item.value;
return $$promises[key];
}
var keysJson = $$storage().getItem(`${this.$$prefix}.keys`);
var keys = keysJson ? angular.fromJson(keysJson) : [];
var itemJson = $$storage().getItem(`${this.$$prefix}.data.${key}`);
let keysJson = $$storage().getItem(`${this.$$prefix}.keys`);
let keys = keysJson ? angular.fromJson(keysJson) : [];
let itemJson = $$storage().getItem(`${this.$$prefix}.data.${key}`);

// Remove existing
if (itemJson) {
Expand All @@ -466,7 +462,7 @@ class CacheFactoryProvider {
});
// Set item
$$storage().setItem(`${this.$$prefix}.data.${key}`, JSON.stringify(item));
var exists = false;
let exists = false;
for (var i = 0; i < keys.length; i++) {
if (keys[i] === key) {
exists = true;
Expand Down Expand Up @@ -527,7 +523,7 @@ class CacheFactoryProvider {
return item.value;
}
} else {
var value = $$data[key] ? $$data[key].value : undefined;
let value = $$data[key] ? $$data[key].value : undefined;
$$lruHeap.remove($$data[key]);
$$expiresHeap.remove($$data[key]);
$$data[key] = null;
Expand Down Expand Up @@ -558,6 +554,7 @@ class CacheFactoryProvider {
}
$$data = {};
}
$$promises = {};
},

removeExpired() {
Expand All @@ -573,7 +570,7 @@ class CacheFactoryProvider {

if ($$storage) {
for (key in expired) {
var itemJson = $$storage().getItem(`${this.$$prefix}.data.${key}`);
let itemJson = $$storage().getItem(`${this.$$prefix}.data.${key}`);
if (itemJson) {
expired[key] = angular.fromJson(itemJson).value;
this.remove(key);
Expand Down Expand Up @@ -622,7 +619,7 @@ class CacheFactoryProvider {
} else {
this.$$capacity = capacity;
}
var removed = {};
let removed = {};
while ($$lruHeap.size() > this.$$capacity) {
removed[$$lruHeap.peek().key] = this.remove($$lruHeap.peek().key);
}
Expand Down

0 comments on commit cbeb9eb

Please sign in to comment.