cache-storage
Advanced tools
Comparing version 1.2.3 to 1.2.4
@@ -64,81 +64,2 @@ // Generated by CoffeeScript 1.6.3 | ||
BrowserLocalStorage.prototype.getMeta = function() { | ||
if (this.meta === null) { | ||
this.getData(); | ||
} | ||
return this.meta; | ||
}; | ||
BrowserLocalStorage.prototype.read = function(key) { | ||
var data; | ||
data = this.getData(); | ||
if (typeof data[key] === 'undefined') { | ||
return null; | ||
} else { | ||
if (this.verify(this.findMeta(key))) { | ||
return data[key]; | ||
} else { | ||
this.remove(key); | ||
return null; | ||
} | ||
} | ||
}; | ||
BrowserLocalStorage.prototype.write = function(key, data, dependencies) { | ||
var all, meta; | ||
if (dependencies == null) { | ||
dependencies = {}; | ||
} | ||
all = this.getData(); | ||
all[key] = data; | ||
meta = this.getMeta(); | ||
meta[key] = dependencies; | ||
this.writeData(all, meta); | ||
return this; | ||
}; | ||
BrowserLocalStorage.prototype.remove = function(key) { | ||
var data, meta; | ||
data = this.getData(); | ||
meta = this.getMeta(); | ||
if (typeof data[key] !== 'undefined') { | ||
delete data[key]; | ||
delete meta[key]; | ||
} | ||
this.writeData(data, meta); | ||
return this; | ||
}; | ||
BrowserLocalStorage.prototype.clean = function(conditions) { | ||
var key, tag, type, typeFn, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2; | ||
typeFn = Object.prototype.toString; | ||
type = typeFn.call(conditions); | ||
if (conditions === Cache.ALL / this.writeData({}, {})) { | ||
} else if (type === '[object Object]') { | ||
if (typeof conditions[Cache.TAGS] !== 'undefined') { | ||
if (typeFn(conditions[Cache.TAGS]) === '[object String]') { | ||
conditions[Cache.TAGS] = [conditions[Cache.TAGS]]; | ||
} | ||
_ref = conditions[Cache.TAGS]; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
tag = _ref[_i]; | ||
_ref1 = this.findKeysByTag(tag); | ||
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { | ||
key = _ref1[_j]; | ||
this.remove(key); | ||
} | ||
} | ||
} | ||
if (typeof conditions[Cache.PRIORITY] !== 'undefined') { | ||
_ref2 = this.findKeysByPriority(conditions[Cache.PRIORITY]); | ||
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { | ||
key = _ref2[_k]; | ||
this.remove(key); | ||
} | ||
} | ||
} | ||
return this; | ||
}; | ||
return BrowserLocalStorage; | ||
@@ -145,0 +66,0 @@ |
@@ -41,3 +41,3 @@ // Generated by CoffeeScript 1.6.3 | ||
data = JSON.parse(fs.readFileSync(file, { | ||
encoding: 'utf-8' | ||
encoding: 'utf8' | ||
})); | ||
@@ -66,81 +66,2 @@ this.data = data.data; | ||
FileStorage.prototype.getMeta = function() { | ||
if (this.meta === null) { | ||
this.getData(); | ||
} | ||
return this.meta; | ||
}; | ||
FileStorage.prototype.read = function(key) { | ||
var data; | ||
data = this.getData(); | ||
if (typeof data[key] === 'undefined') { | ||
return null; | ||
} else { | ||
if (this.verify(this.findMeta(key))) { | ||
return data[key]; | ||
} else { | ||
this.remove(key); | ||
return null; | ||
} | ||
} | ||
}; | ||
FileStorage.prototype.write = function(key, data, dependencies) { | ||
var all, meta; | ||
if (dependencies == null) { | ||
dependencies = {}; | ||
} | ||
all = this.getData(); | ||
all[key] = data; | ||
meta = this.getMeta(); | ||
meta[key] = dependencies; | ||
this.writeData(all, meta); | ||
return this; | ||
}; | ||
FileStorage.prototype.remove = function(key) { | ||
var data, meta; | ||
data = this.getData(); | ||
meta = this.getMeta(); | ||
if (typeof data[key] !== 'undefined') { | ||
delete data[key]; | ||
delete meta[key]; | ||
} | ||
this.writeData(data, meta); | ||
return this; | ||
}; | ||
FileStorage.prototype.clean = function(conditions) { | ||
var key, tag, type, typeFn, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2; | ||
typeFn = Object.prototype.toString; | ||
type = typeFn.call(conditions); | ||
if (conditions === Cache.ALL) { | ||
this.writeData({}, {}); | ||
} else if (type === '[object Object]') { | ||
if (typeof conditions[Cache.TAGS] !== 'undefined') { | ||
if (typeFn(conditions[Cache.TAGS]) === '[object String]') { | ||
conditions[Cache.TAGS] = [conditions[Cache.TAGS]]; | ||
} | ||
_ref = conditions[Cache.TAGS]; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
tag = _ref[_i]; | ||
_ref1 = this.findKeysByTag(tag); | ||
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { | ||
key = _ref1[_j]; | ||
this.remove(key); | ||
} | ||
} | ||
} | ||
if (typeof conditions[Cache.PRIORITY] !== 'undefined') { | ||
_ref2 = this.findKeysByPriority(conditions[Cache.PRIORITY]); | ||
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { | ||
key = _ref2[_k]; | ||
this.remove(key); | ||
} | ||
} | ||
} | ||
return this; | ||
}; | ||
return FileStorage; | ||
@@ -147,0 +68,0 @@ |
@@ -17,4 +17,2 @@ // Generated by CoffeeScript 1.6.3 | ||
Storage = (function() { | ||
function Storage() {} | ||
Storage.prototype.cache = null; | ||
@@ -26,23 +24,85 @@ | ||
function Storage() { | ||
if (typeof this.getData === 'undefined' || typeof this.writeData === 'undefined') { | ||
throw new Error('Cache storage: you have to implement methods getData and writeData.'); | ||
} | ||
} | ||
Storage.prototype.read = function(key) { | ||
throw new Error('Cache storage: read method is not implemented.'); | ||
var data; | ||
data = this.getData(); | ||
if (typeof data[key] === 'undefined') { | ||
return null; | ||
} else { | ||
if (this.verify(this.findMeta(key))) { | ||
return data[key]; | ||
} else { | ||
this.remove(key); | ||
return null; | ||
} | ||
} | ||
}; | ||
Storage.prototype.write = function(key, data, dependencies) { | ||
var all, meta; | ||
if (dependencies == null) { | ||
dependencies = {}; | ||
} | ||
throw new Error('Cache storage: write method is not implemented.'); | ||
all = this.getData(); | ||
all[key] = data; | ||
meta = this.getMeta(); | ||
meta[key] = dependencies; | ||
this.writeData(all, meta); | ||
return this; | ||
}; | ||
Storage.prototype.remove = function(key) { | ||
throw new Error('Cache storage: remove method is not implemented.'); | ||
var data, meta; | ||
data = this.getData(); | ||
meta = this.getMeta(); | ||
if (typeof data[key] !== 'undefined') { | ||
delete data[key]; | ||
delete meta[key]; | ||
} | ||
this.writeData(data, meta); | ||
return this; | ||
}; | ||
Storage.prototype.clean = function(conditions) { | ||
throw new Error('Cache storage: clean method is not implemented'); | ||
var key, tag, type, typeFn, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2; | ||
typeFn = Object.prototype.toString; | ||
type = typeFn.call(conditions); | ||
if (conditions === Cache.ALL) { | ||
this.writeData({}, {}); | ||
} else if (type === '[object Object]') { | ||
if (typeof conditions[Cache.TAGS] !== 'undefined') { | ||
if (typeFn(conditions[Cache.TAGS]) === '[object String]') { | ||
conditions[Cache.TAGS] = [conditions[Cache.TAGS]]; | ||
} | ||
_ref = conditions[Cache.TAGS]; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
tag = _ref[_i]; | ||
_ref1 = this.findKeysByTag(tag); | ||
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { | ||
key = _ref1[_j]; | ||
this.remove(key); | ||
} | ||
} | ||
} | ||
if (typeof conditions[Cache.PRIORITY] !== 'undefined') { | ||
_ref2 = this.findKeysByPriority(conditions[Cache.PRIORITY]); | ||
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { | ||
key = _ref2[_k]; | ||
this.remove(key); | ||
} | ||
} | ||
} | ||
return this; | ||
}; | ||
Storage.prototype.getMeta = function() { | ||
throw new Error('Cache storage: getMeta method is not implemented'); | ||
if (this.meta === null) { | ||
this.getData(); | ||
} | ||
return this.meta; | ||
}; | ||
@@ -49,0 +109,0 @@ |
{ | ||
"name": "cache-storage", | ||
"description": "Cache storage for node js", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"author": { | ||
@@ -24,10 +24,11 @@ "name": "David Kudera", | ||
"dependencies": { | ||
"moment": "2.1.0" | ||
"moment": "latest" | ||
}, | ||
"devDependencies": { | ||
"should": "1.2.2" | ||
"mocha": "latest", | ||
"chai": "latest" | ||
}, | ||
"scripts": { | ||
"test": "cd ./test; mocha ./index.js --reporter spec;" | ||
"test": "cd ./test; echo \"Testing in node:\"; mocha ./node/index.js --reporter spec; echo \"Testing in browser:\"; mocha-phantomjs ./browser/index.html;" | ||
} | ||
} |
@@ -27,2 +27,4 @@ # cache-storage | ||
More storages will be added in future. | ||
## Loading & saving | ||
@@ -128,3 +130,3 @@ | ||
``` | ||
$ npm test | ||
``` | ||
@@ -134,2 +136,8 @@ | ||
* 1.2.4 | ||
+ Rewritten tests | ||
+ Added tests for browser | ||
+ Refactoring storages | ||
+ Bad encoding in FileStorage | ||
* 1.2.3 | ||
@@ -136,0 +144,0 @@ + Shortcut for base Storage class |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
123274
29
2894
172
2
8
1
+ Addedmoment@2.30.1(transitive)
- Removedmoment@2.1.0(transitive)
Updatedmoment@latest