file-entry-cache 1.2.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -14
- package/cache.js +11 -5
- package/changelog.md +42 -8
- package/package.json +23 -12
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# file-entry-cache
|
|
2
|
-
> Super simple cache for file metadata, useful for process that work o a given series of files
|
|
2
|
+
> Super simple cache for file metadata, useful for process that work o a given series of files
|
|
3
3
|
> and that only need to repeat the job on the changed ones since the previous run of the process — Edit
|
|
4
4
|
|
|
5
5
|
[](https://npmjs.org/package/file-entry-cache)
|
|
@@ -14,7 +14,7 @@ npm i --save file-entry-cache
|
|
|
14
14
|
## Usage
|
|
15
15
|
|
|
16
16
|
```js
|
|
17
|
-
// loads the cache, if one does not exists for the given
|
|
17
|
+
// loads the cache, if one does not exists for the given
|
|
18
18
|
// Id a new one will be prepared to be created
|
|
19
19
|
var fileEntryCache = require('file-entry-cache');
|
|
20
20
|
|
|
@@ -25,18 +25,23 @@ var files = expand('../fixtures/*.txt');
|
|
|
25
25
|
// the first time this method is called, will return all the files
|
|
26
26
|
var oFiles = cache.getUpdatedFiles(files);
|
|
27
27
|
|
|
28
|
-
// this will persist this to disk checking each file stats and
|
|
28
|
+
// this will persist this to disk checking each file stats and
|
|
29
29
|
// updating the meta attributes `size` and `mtime`.
|
|
30
30
|
// custom fields could also be added to the meta object and will be persisted
|
|
31
31
|
// in order to retrieve them later
|
|
32
|
-
cache.reconcile();
|
|
32
|
+
cache.reconcile();
|
|
33
|
+
|
|
34
|
+
// use this if you want the non visited file entries to be kept in the cache
|
|
35
|
+
// for more than one execution
|
|
36
|
+
//
|
|
37
|
+
// cache.reconcile( true /* noPrune */)
|
|
33
38
|
|
|
34
39
|
// on a second run
|
|
35
40
|
var cache2 = fileEntryCache.create('testCache');
|
|
36
41
|
|
|
37
42
|
// will return now only the files that were modified or none
|
|
38
43
|
// if no files were modified previous to the execution of this function
|
|
39
|
-
var oFiles = cache.getUpdatedFiles(files);
|
|
44
|
+
var oFiles = cache.getUpdatedFiles(files);
|
|
40
45
|
|
|
41
46
|
// if you want to prevent a file from being considered non modified
|
|
42
47
|
// something useful if a file failed some sort of validation
|
|
@@ -64,21 +69,21 @@ entry = {
|
|
|
64
69
|
|
|
65
70
|
## Motivation for this module
|
|
66
71
|
|
|
67
|
-
I needed a super simple and dumb **in-memory cache** with optional disk persistence (write-back cache) in order to make
|
|
72
|
+
I needed a super simple and dumb **in-memory cache** with optional disk persistence (write-back cache) in order to make
|
|
68
73
|
a script that will beautify files with `esformatter` to execute only on the files that were changed since the last run.
|
|
69
74
|
|
|
70
75
|
In doing so the process of beautifying files was reduced from several seconds to a small fraction of a second.
|
|
71
76
|
|
|
72
|
-
This module uses [flat-cache](https://www.npmjs.com/package/flat-cache) a super simple `key/value` cache storage with
|
|
77
|
+
This module uses [flat-cache](https://www.npmjs.com/package/flat-cache) a super simple `key/value` cache storage with
|
|
73
78
|
optional file persistance.
|
|
74
79
|
|
|
75
|
-
The main idea is to read the files when the task begins, apply the transforms required, and if the process succeed,
|
|
76
|
-
then store the new state of the files. The next time this module request for `getChangedFiles` will return only
|
|
80
|
+
The main idea is to read the files when the task begins, apply the transforms required, and if the process succeed,
|
|
81
|
+
then store the new state of the files. The next time this module request for `getChangedFiles` will return only
|
|
77
82
|
the files that were modified. Making the process to end faster.
|
|
78
83
|
|
|
79
84
|
This module could also be used by processes that modify the files applying a transform, in that case the result of the
|
|
80
|
-
transform could be stored in the `meta` field, of the entries. Anything added to the meta field will be persisted.
|
|
81
|
-
Those processes won't need to call `getChangedFiles` they will instead call `normalizeEntries` that will return the
|
|
85
|
+
transform could be stored in the `meta` field, of the entries. Anything added to the meta field will be persisted.
|
|
86
|
+
Those processes won't need to call `getChangedFiles` they will instead call `normalizeEntries` that will return the
|
|
82
87
|
entries with a `changed` field that can be used to determine if the file was changed or not. If it was not changed
|
|
83
88
|
the transformed stored data could be used instead of actually applying the transformation, saving time in case of only
|
|
84
89
|
a few files changed.
|
|
@@ -86,10 +91,16 @@ a few files changed.
|
|
|
86
91
|
In the worst case scenario all the files will be processed. In the best case scenario only a few of them will be processed.
|
|
87
92
|
|
|
88
93
|
## Important notes
|
|
89
|
-
- The values set on the meta attribute of the entries should be `stringify-able` ones,
|
|
90
|
-
- All the changes to the cache state are done to memory first and only persisted after reconcile
|
|
94
|
+
- The values set on the meta attribute of the entries should be `stringify-able` ones if possible, flat-cache uses `circular-json` to try to persist circular structures, but this should be considered experimental. The best results are always obtained with non circular values
|
|
95
|
+
- All the changes to the cache state are done to memory first and only persisted after reconcile.
|
|
96
|
+
- By default non visited entries are removed from the cache. This is done to prevent the file from growing too much. If this is not an issue and
|
|
97
|
+
you prefer to do a manual pruning of the cache files, you can pass `true` to the `reconcile` call. Like this:
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
cache.reconcile( true /* noPrune */ );
|
|
101
|
+
```
|
|
91
102
|
|
|
92
|
-
## License
|
|
103
|
+
## License
|
|
93
104
|
|
|
94
105
|
MIT
|
|
95
106
|
|
package/cache.js
CHANGED
|
@@ -11,10 +11,15 @@ module.exports = {
|
|
|
11
11
|
var fs = require( 'fs' );
|
|
12
12
|
var flatCache = require( 'flat-cache' );
|
|
13
13
|
var cache = flatCache.load( cacheId, _path );
|
|
14
|
-
var assign = require( '
|
|
14
|
+
var assign = require( 'object-assign' );
|
|
15
15
|
var normalizedEntries = { };
|
|
16
16
|
|
|
17
17
|
return {
|
|
18
|
+
/**
|
|
19
|
+
* the flat cache storage used to persist the metadata of the `files
|
|
20
|
+
* @type {Object}
|
|
21
|
+
*/
|
|
22
|
+
cache: cache,
|
|
18
23
|
/**
|
|
19
24
|
* Return whether or not a file has changed since last time reconcile was called.
|
|
20
25
|
* @method hasFileChanged
|
|
@@ -145,7 +150,6 @@ module.exports = {
|
|
|
145
150
|
*/
|
|
146
151
|
deleteCacheFile: function () {
|
|
147
152
|
cache.removeCacheFile();
|
|
148
|
-
//flatCache.clearCacheById(cacheId);
|
|
149
153
|
},
|
|
150
154
|
|
|
151
155
|
/**
|
|
@@ -157,16 +161,18 @@ module.exports = {
|
|
|
157
161
|
},
|
|
158
162
|
/**
|
|
159
163
|
* Sync the files and persist them to the cache
|
|
160
|
-
*
|
|
164
|
+
* @param [noPrune=false] {Boolean} whether to remove non visited/saved entries
|
|
161
165
|
* @method reconcile
|
|
162
166
|
*/
|
|
163
|
-
reconcile: function () {
|
|
167
|
+
reconcile: function ( noPrune ) {
|
|
164
168
|
var entries = normalizedEntries;
|
|
165
169
|
|
|
166
170
|
var keys = Object.keys( entries );
|
|
171
|
+
|
|
167
172
|
if ( keys.length === 0 ) {
|
|
168
173
|
return;
|
|
169
174
|
}
|
|
175
|
+
|
|
170
176
|
keys.forEach( function ( entryName ) {
|
|
171
177
|
var cacheEntry = entries[ entryName ];
|
|
172
178
|
var stat = fs.statSync( cacheEntry.key );
|
|
@@ -179,7 +185,7 @@ module.exports = {
|
|
|
179
185
|
cache.setKey( entryName, meta );
|
|
180
186
|
} );
|
|
181
187
|
|
|
182
|
-
cache.save();
|
|
188
|
+
cache.save( noPrune );
|
|
183
189
|
}
|
|
184
190
|
};
|
|
185
191
|
}
|
package/changelog.md
CHANGED
|
@@ -1,35 +1,69 @@
|
|
|
1
1
|
|
|
2
2
|
# file-entry-cache - Changelog
|
|
3
|
+
## v1.3.1
|
|
4
|
+
- **Build Scripts Changes**
|
|
5
|
+
- remove older node version - [0a26ac4]( https://github.com/royriojas/file-entry-cache/commit/0a26ac4 ), [Roy Riojas](https://github.com/Roy Riojas), 01/08/2016 06:09:17
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## v1.3.0
|
|
9
|
+
- **Features**
|
|
10
|
+
- Add an option to not prune non visited keys. Closes [#2](https://github.com/royriojas/file-entry-cache/issues/2) - [b1a64db]( https://github.com/royriojas/file-entry-cache/commit/b1a64db ), [Roy Riojas](https://github.com/Roy Riojas), 01/08/2016 05:52:12
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## v1.2.4
|
|
14
|
+
- **Enhancements**
|
|
15
|
+
- Expose the flat-cache instance - [f34c557]( https://github.com/royriojas/file-entry-cache/commit/f34c557 ), [royriojas](https://github.com/royriojas), 23/09/2015 20:26:33
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
## v1.2.3
|
|
19
|
+
- **Build Scripts Changes**
|
|
20
|
+
- update flat-cache dep - [cc7b9ce]( https://github.com/royriojas/file-entry-cache/commit/cc7b9ce ), [royriojas](https://github.com/royriojas), 11/09/2015 18:04:44
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## v1.2.2
|
|
24
|
+
- **Build Scripts Changes**
|
|
25
|
+
- Add changelogx section to package.json - [a3916ff]( https://github.com/royriojas/file-entry-cache/commit/a3916ff ), [royriojas](https://github.com/royriojas), 11/09/2015 18:00:26
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## v1.2.1
|
|
29
|
+
- **Build Scripts Changes**
|
|
30
|
+
- update flat-cache dep - [e49b0d4]( https://github.com/royriojas/file-entry-cache/commit/e49b0d4 ), [royriojas](https://github.com/royriojas), 11/09/2015 17:55:25
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
- **Other changes**
|
|
34
|
+
- Update dependencies Replaced lodash.assign with smaller object-assign Fixed tests for windows - [0ad3000]( https://github.com/royriojas/file-entry-cache/commit/0ad3000 ), [Bogdan Chadkin](https://github.com/Bogdan Chadkin), 11/09/2015 17:44:18
|
|
35
|
+
|
|
36
|
+
|
|
3
37
|
## v1.2.0
|
|
4
38
|
- **Features**
|
|
5
|
-
- analyzeFiles now returns also the files that were removed - [6ac2431]( https://github.com/
|
|
39
|
+
- analyzeFiles now returns also the files that were removed - [6ac2431]( https://github.com/royriojas/file-entry-cache/commit/6ac2431 ), [royriojas](https://github.com/royriojas), 04/09/2015 14:40:53
|
|
6
40
|
|
|
7
41
|
|
|
8
42
|
## v1.1.1
|
|
9
43
|
- **Features**
|
|
10
|
-
- Add method to check if a file hasChanged - [3640e2b]( https://github.com/
|
|
44
|
+
- Add method to check if a file hasChanged - [3640e2b]( https://github.com/royriojas/file-entry-cache/commit/3640e2b ), [Roy Riojas](https://github.com/Roy Riojas), 30/08/2015 07:33:32
|
|
11
45
|
|
|
12
46
|
|
|
13
47
|
## v1.1.0
|
|
14
48
|
- **Features**
|
|
15
|
-
- Create the cache directly from a file path - [a23de61]( https://github.com/
|
|
49
|
+
- Create the cache directly from a file path - [a23de61]( https://github.com/royriojas/file-entry-cache/commit/a23de61 ), [Roy Riojas](https://github.com/Roy Riojas), 30/08/2015 06:41:33
|
|
16
50
|
|
|
17
51
|
|
|
18
|
-
- Add a method to remove an entry from the filecache - [7af29fc]( https://github.com/
|
|
52
|
+
- Add a method to remove an entry from the filecache - [7af29fc]( https://github.com/royriojas/file-entry-cache/commit/7af29fc ), [Roy Riojas](https://github.com/Roy Riojas), 03/03/2015 02:25:32
|
|
19
53
|
|
|
20
54
|
|
|
21
|
-
- cache module finished - [1f95544]( https://github.com/
|
|
55
|
+
- cache module finished - [1f95544]( https://github.com/royriojas/file-entry-cache/commit/1f95544 ), [Roy Riojas](https://github.com/Roy Riojas), 02/03/2015 04:08:08
|
|
22
56
|
|
|
23
57
|
|
|
24
58
|
- **Build Scripts Changes**
|
|
25
|
-
- set the version for the first release - [7472eaa]( https://github.com/
|
|
59
|
+
- set the version for the first release - [7472eaa]( https://github.com/royriojas/file-entry-cache/commit/7472eaa ), [Roy Riojas](https://github.com/Roy Riojas), 02/03/2015 04:29:54
|
|
26
60
|
|
|
27
61
|
|
|
28
62
|
- **Documentation**
|
|
29
|
-
- Updated documentation - [557358f]( https://github.com/
|
|
63
|
+
- Updated documentation - [557358f]( https://github.com/royriojas/file-entry-cache/commit/557358f ), [Roy Riojas](https://github.com/Roy Riojas), 02/03/2015 04:29:29
|
|
30
64
|
|
|
31
65
|
|
|
32
66
|
- **Other changes**
|
|
33
|
-
- Initial commit - [3d5f42b]( https://github.com/
|
|
67
|
+
- Initial commit - [3d5f42b]( https://github.com/royriojas/file-entry-cache/commit/3d5f42b ), [Roy Riojas](https://github.com/Roy Riojas), 02/03/2015 00:58:29
|
|
34
68
|
|
|
35
69
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "file-entry-cache",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Super simple cache for file metadata, useful for process that work o a given series of files and that only need to repeat the job on the changed ones since the previous run of the process",
|
|
5
5
|
"repository": "royriojas/file-entry-cache",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,20 +16,20 @@
|
|
|
16
16
|
"node": ">=0.10.0"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
|
-
"beautify": "esbeautifier 'cache.js' '
|
|
20
|
-
"beautify-check": "
|
|
19
|
+
"beautify": "esbeautifier 'cache.js' 'test/**/*.js'",
|
|
20
|
+
"beautify-check": "npm run beautify -- -k",
|
|
21
21
|
"eslint": "eslinter 'cache.js' 'specs/**/*.js'",
|
|
22
22
|
"lint": "npm run beautify && npm run eslint",
|
|
23
23
|
"verify": "npm run beautify-check && npm run eslint",
|
|
24
24
|
"install-hooks": "prepush install && changelogx install-hook && precommit install",
|
|
25
25
|
"changelog": "changelogx -f markdown -o ./changelog.md",
|
|
26
26
|
"do-changelog": "npm run changelog && git add ./changelog.md && git commit -m 'DOC: Generate changelog' --no-verify",
|
|
27
|
-
"pre-v": "npm run
|
|
27
|
+
"pre-v": "npm run test",
|
|
28
28
|
"post-v": "npm run do-changelog && git push --no-verify && git push --tags --no-verify",
|
|
29
29
|
"bump-major": "npm run pre-v && npm version major -m 'BLD: Release v%s' && npm run post-v",
|
|
30
30
|
"bump-minor": "npm run pre-v && npm version minor -m 'BLD: Release v%s' && npm run post-v",
|
|
31
31
|
"bump-patch": "npm run pre-v && npm version patch -m 'BLD: Release v%s' && npm run post-v",
|
|
32
|
-
"test": "mocha -R spec test/specs",
|
|
32
|
+
"test": "npm run verify && mocha -R spec test/specs",
|
|
33
33
|
"cover": "istanbul cover test/runner.js html text-summary",
|
|
34
34
|
"watch": "watch-run -i -p 'test/specs/**/*.js' istanbul cover test/runner.js html text-summary"
|
|
35
35
|
},
|
|
@@ -47,27 +47,38 @@
|
|
|
47
47
|
"key value",
|
|
48
48
|
"cache"
|
|
49
49
|
],
|
|
50
|
+
"changelogx": {
|
|
51
|
+
"ignoreRegExp": [
|
|
52
|
+
"BLD: Release",
|
|
53
|
+
"DOC: Generate Changelog",
|
|
54
|
+
"Generated Changelog"
|
|
55
|
+
],
|
|
56
|
+
"issueIDRegExp": "#(\\d+)",
|
|
57
|
+
"commitURL": "https://github.com/royriojas/file-entry-cache/commit/{0}",
|
|
58
|
+
"authorURL": "https://github.com/{0}",
|
|
59
|
+
"issueIDURL": "https://github.com/royriojas/file-entry-cache/issues/{0}",
|
|
60
|
+
"projectName": "file-entry-cache"
|
|
61
|
+
},
|
|
50
62
|
"devDependencies": {
|
|
51
|
-
"chai": "^2.
|
|
63
|
+
"chai": "^3.2.0",
|
|
52
64
|
"changelogx": "^1.0.18",
|
|
53
65
|
"commander": "^2.6.0",
|
|
54
|
-
"del": "^
|
|
66
|
+
"del": "^2.0.2",
|
|
55
67
|
"esbeautifier": "^4.2.11",
|
|
56
68
|
"eslinter": "^2.3.3",
|
|
57
|
-
"glob-expand": "0.0
|
|
69
|
+
"glob-expand": "^0.1.0",
|
|
58
70
|
"istanbul": "^0.3.6",
|
|
59
71
|
"mocha": "^2.1.0",
|
|
60
72
|
"precommit": "^1.1.5",
|
|
61
73
|
"prepush": "^3.1.4",
|
|
62
74
|
"proxyquire": "^1.3.1",
|
|
63
|
-
"read-file": "^0.1.2",
|
|
64
75
|
"sinon": "^1.12.2",
|
|
65
76
|
"sinon-chai": "^2.7.0",
|
|
66
77
|
"watch-run": "^1.2.1",
|
|
67
|
-
"write": "^0.
|
|
78
|
+
"write": "^0.3.1"
|
|
68
79
|
},
|
|
69
80
|
"dependencies": {
|
|
70
|
-
"flat-cache": "^1.
|
|
71
|
-
"
|
|
81
|
+
"flat-cache": "^1.2.1",
|
|
82
|
+
"object-assign": "^4.0.1"
|
|
72
83
|
}
|
|
73
84
|
}
|