hot-file-cache
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -0,1 +1,5 @@ | ||
## 0.0.6 | ||
- Set `atomic:false` by default for faster cache invalidation | ||
## 0.0.5 | ||
@@ -2,0 +6,0 @@ |
10
index.js
@@ -13,2 +13,4 @@ var path = require('path'); | ||
} | ||
// Turn atomic off by default | ||
this.options.atomic = this.options.atomic === undefined ? false : this.options.atomic; | ||
// Turn string patterns into array | ||
@@ -19,3 +21,3 @@ this.patterns = [].concat(patterns); | ||
// Remove fileMap from chokidar options | ||
delete (options.fileProcessors); | ||
delete (options.fileProcessor); | ||
// Initialize cache | ||
@@ -104,6 +106,8 @@ this.cache = {}; | ||
/** | ||
* invalidate cache | ||
* Invalidate cache | ||
*/ | ||
HotFileCache.prototype.invalidateCache = function (reason, filepath) { | ||
this.emit('cache-revoked', filepath); | ||
if (this.cache[filepath]) { | ||
this.emit('cache-revoked', filepath); | ||
} | ||
delete this.cache[filepath]; | ||
@@ -110,0 +114,0 @@ }; |
{ | ||
"name": "hot-file-cache", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "A file cache for development which will invalidate automatically if the source changes", | ||
@@ -9,3 +9,4 @@ "main": "index.js", | ||
"test": "ava", | ||
"posttest": "semistandard index.js" | ||
"posttest": "semistandard index.js", | ||
"puml": "puml generate flow.puml -o flow.png" | ||
}, | ||
@@ -33,2 +34,3 @@ "files": [ | ||
"ncp": "^2.0.0", | ||
"node-plantuml": "^0.4.4", | ||
"rimraf": "^2.5.2", | ||
@@ -35,0 +37,0 @@ "semistandard": "^8.0.0" |
@@ -8,2 +8,3 @@ Hot File Cache | ||
Installation | ||
@@ -22,4 +23,4 @@ ------------ | ||
```javascript | ||
var cache = new HotFileCache('*.md', {cwd: dir}); | ||
cache.readFile('README.md').then(function(content) { | ||
var hfc = new HotFileCache('*.md', {cwd: dir}); | ||
hfc.readFile('README.md').then(function(content) { | ||
console.log(content); | ||
@@ -33,9 +34,11 @@ }); | ||
```javascript | ||
var cache = new HotFileCache('*.md', { | ||
var hfc = new HotFileCache('*.json', { | ||
cwd: dir, | ||
fileProcessor: function (fileContent) { | ||
// the fileProcessor will be executed only once per file | ||
fileProcessor: function (filename, fileContent) { | ||
// the return value could also be a promise | ||
return JSON.parse(fileContent); | ||
} | ||
}); | ||
cache.readFile('README.md').then(function(content) { | ||
hfc.readFile('demo.json').then(function(content) { | ||
console.log(content); | ||
@@ -49,3 +52,32 @@ }); | ||
Visualisation | ||
----------- | ||
```javascript | ||
var hfc = new HotFileCache('*.json', { | ||
cwd: dir, | ||
fileProcessor: function process (filename, fileContent) { | ||
return JSON.parse(fileContent); | ||
} | ||
}); | ||
hfc.readFile('demo.json') // 1 | ||
.then(function(content) { | ||
console.log(content); | ||
}); | ||
hfc.readFile('demo.json') // 2 | ||
.then(function(content) { | ||
console.log(content); | ||
}); | ||
hfc.readFile('demo.json') // 3 | ||
.then(function(content) { | ||
console.log(content); | ||
}); | ||
hfc.readFile('demo.json') // 4 | ||
.then(function(content) { | ||
console.log(content); | ||
}); | ||
``` | ||
[![Concept flow uml](https://raw.githubusercontent.com/jantimon/hot-file-cache/master/flow.png)](https://github.com/jantimon/hot-file-cache/blob/master/flow.puml) | ||
# Changelog | ||
@@ -63,2 +95,2 @@ | ||
This project is licensed under [MIT](https://github.com/jantimon/hot-file-cache/blob/master/LICENSE). | ||
This project is licensed under [MIT](https://github.com/jantimon/hot-file-cache/blob/master/LICENSE). |
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
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
7764
105
92
6