file-entry-cache 1.3.1 → 2.0.0

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.
Files changed (3) hide show
  1. package/cache.js +35 -11
  2. package/changelog.md +5 -0
  3. package/package.json +2 -2
package/cache.js CHANGED
@@ -14,6 +14,22 @@ module.exports = {
14
14
  var assign = require( 'object-assign' );
15
15
  var normalizedEntries = { };
16
16
 
17
+ var removeNotFoundFiles = function removeNotFoundFiles() {
18
+ const cachedEntries = cache.keys();
19
+ // remove not found entries
20
+ cachedEntries.forEach( function remover( fPath ) {
21
+ try {
22
+ fs.statSync( fPath );
23
+ } catch (err) {
24
+ if ( err.code === 'ENOENT' ) {
25
+ cache.removeKey( fPath );
26
+ }
27
+ }
28
+ } );
29
+ };
30
+
31
+ removeNotFoundFiles();
32
+
17
33
  return {
18
34
  /**
19
35
  * the flat cache storage used to persist the metadata of the `files
@@ -161,12 +177,12 @@ module.exports = {
161
177
  },
162
178
  /**
163
179
  * Sync the files and persist them to the cache
164
- * @param [noPrune=false] {Boolean} whether to remove non visited/saved entries
165
180
  * @method reconcile
166
181
  */
167
- reconcile: function ( noPrune ) {
168
- var entries = normalizedEntries;
182
+ reconcile: function () {
183
+ removeNotFoundFiles();
169
184
 
185
+ var entries = normalizedEntries;
170
186
  var keys = Object.keys( entries );
171
187
 
172
188
  if ( keys.length === 0 ) {
@@ -175,17 +191,25 @@ module.exports = {
175
191
 
176
192
  keys.forEach( function ( entryName ) {
177
193
  var cacheEntry = entries[ entryName ];
178
- var stat = fs.statSync( cacheEntry.key );
179
194
 
180
- var meta = assign( cacheEntry.meta, {
181
- size: stat.size,
182
- mtime: stat.mtime.getTime()
183
- } );
184
-
185
- cache.setKey( entryName, meta );
195
+ try {
196
+ var stat = fs.statSync( cacheEntry.key );
197
+ var meta = assign( cacheEntry.meta, {
198
+ size: stat.size,
199
+ mtime: stat.mtime.getTime()
200
+ } );
201
+
202
+ cache.setKey( entryName, meta );
203
+ } catch (err) {
204
+ // if the file does not exists we don't save it
205
+ // other errors are just thrown
206
+ if ( err.code !== 'ENOENT' ) {
207
+ throw err;
208
+ }
209
+ }
186
210
  } );
187
211
 
188
- cache.save( noPrune );
212
+ cache.save( true );
189
213
  }
190
214
  };
191
215
  }
package/changelog.md CHANGED
@@ -1,5 +1,10 @@
1
1
 
2
2
  # file-entry-cache - Changelog
3
+ ## v2.0.0
4
+ - **Features**
5
+ - do not persist and prune removed files from cache. Relates to [#2](https://github.com/royriojas/file-entry-cache/issues/2) - [408374d]( https://github.com/royriojas/file-entry-cache/commit/408374d ), [Roy Riojas](https://github.com/Roy Riojas), 16/08/2016 15:47:58
6
+
7
+
3
8
  ## v1.3.1
4
9
  - **Build Scripts Changes**
5
10
  - 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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "file-entry-cache",
3
- "version": "1.3.1",
3
+ "version": "2.0.0",
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",
@@ -29,7 +29,7 @@
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": "npm run verify && mocha -R spec test/specs",
32
+ "test": "npm run verify --silent && 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
  },