flat-cache 1.2.1 → 1.3.2
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 +3 -1
- package/cache.js +21 -6
- package/changelog.md +130 -5
- package/package.json +8 -8
- package/utils.js +10 -0
package/README.md
CHANGED
|
@@ -24,6 +24,9 @@ cache.setKey('key', { foo: 'var' });
|
|
|
24
24
|
// get a key from the cache
|
|
25
25
|
cache.getKey('key') // { foo: 'var' }
|
|
26
26
|
|
|
27
|
+
// fetch the entire persisted object
|
|
28
|
+
cache.all() // { 'key': { foo: 'var' } }
|
|
29
|
+
|
|
27
30
|
// remove a key
|
|
28
31
|
cache.removeKey('key'); // removes a key from the cache
|
|
29
32
|
|
|
@@ -68,4 +71,3 @@ MIT
|
|
|
68
71
|
## Changelog
|
|
69
72
|
|
|
70
73
|
[changelog](./changelog.md)
|
|
71
|
-
|
package/cache.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
var path = require( 'path' );
|
|
2
2
|
var fs = require( 'graceful-fs' );
|
|
3
3
|
var del = require( 'del' ).sync;
|
|
4
|
-
var
|
|
5
|
-
var writeJSON =
|
|
4
|
+
var utils = require( './utils' );
|
|
5
|
+
var writeJSON = utils.writeJSON;
|
|
6
6
|
|
|
7
7
|
var cache = {
|
|
8
8
|
/**
|
|
@@ -22,7 +22,7 @@ var cache = {
|
|
|
22
22
|
me._pathToFile = cacheDir ? path.resolve( cacheDir, docId ) : path.resolve( __dirname, './.cache/', docId );
|
|
23
23
|
|
|
24
24
|
if ( fs.existsSync( me._pathToFile ) ) {
|
|
25
|
-
me._persisted =
|
|
25
|
+
me._persisted = utils.tryParse( me._pathToFile, { } );
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
|
|
@@ -39,6 +39,15 @@ var cache = {
|
|
|
39
39
|
me.load( fName, dir );
|
|
40
40
|
},
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Returns the entire persisted object
|
|
44
|
+
* @method all
|
|
45
|
+
* @returns {*}
|
|
46
|
+
*/
|
|
47
|
+
all: function () {
|
|
48
|
+
return this._persisted;
|
|
49
|
+
},
|
|
50
|
+
|
|
42
51
|
keys: function () {
|
|
43
52
|
return Object.keys( this._persisted );
|
|
44
53
|
},
|
|
@@ -116,7 +125,9 @@ var cache = {
|
|
|
116
125
|
* @return {Boolean} true or false if the file was successfully deleted
|
|
117
126
|
*/
|
|
118
127
|
removeCacheFile: function () {
|
|
119
|
-
return del( this._pathToFile, {
|
|
128
|
+
return del( this._pathToFile, {
|
|
129
|
+
force: true
|
|
130
|
+
} );
|
|
120
131
|
},
|
|
121
132
|
/**
|
|
122
133
|
* Destroy the file cache and cache content.
|
|
@@ -174,7 +185,9 @@ module.exports = {
|
|
|
174
185
|
*/
|
|
175
186
|
clearCacheById: function ( docId, cacheDir ) {
|
|
176
187
|
var filePath = cacheDir ? path.resolve( cacheDir, docId ) : path.resolve( __dirname, './.cache/', docId );
|
|
177
|
-
return del( filePath, {
|
|
188
|
+
return del( filePath, {
|
|
189
|
+
force: true
|
|
190
|
+
} ).length > 0;
|
|
178
191
|
},
|
|
179
192
|
/**
|
|
180
193
|
* Remove all cache stored in the cache directory
|
|
@@ -183,6 +196,8 @@ module.exports = {
|
|
|
183
196
|
*/
|
|
184
197
|
clearAll: function ( cacheDir ) {
|
|
185
198
|
var filePath = cacheDir ? path.resolve( cacheDir ) : path.resolve( __dirname, './.cache/' );
|
|
186
|
-
return del( filePath, {
|
|
199
|
+
return del( filePath, {
|
|
200
|
+
force: true
|
|
201
|
+
} ).length > 0;
|
|
187
202
|
}
|
|
188
203
|
};
|
package/changelog.md
CHANGED
|
@@ -1,5 +1,68 @@
|
|
|
1
1
|
|
|
2
2
|
# flat-cache - Changelog
|
|
3
|
+
## v1.3.2
|
|
4
|
+
- **Refactoring**
|
|
5
|
+
- remove yarn.lock file - [704c6c4]( https://github.com/royriojas/flat-cache/commit/704c6c4 ), [Roy Riojas](https://github.com/Roy Riojas), 07/11/2018 18:41:08
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
- **undefined**
|
|
9
|
+
- replace circular-json with flatted ([#23](https://github.com/royriojas/flat-cache/issues/23))" - [db12d74]( https://github.com/royriojas/flat-cache/commit/db12d74 ), [Roy Riojas](https://github.com/Roy Riojas), 07/11/2018 18:40:39
|
|
10
|
+
|
|
11
|
+
This reverts commit 00f689277a75e85fef28e6a048fad227afc525e6.
|
|
12
|
+
|
|
13
|
+
## v1.3.1
|
|
14
|
+
- **Refactoring**
|
|
15
|
+
- upgrade deps to remove some security warnings - [f405719]( https://github.com/royriojas/flat-cache/commit/f405719 ), [Roy Riojas](https://github.com/Roy Riojas), 06/11/2018 15:07:31
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
- **Bug Fixes**
|
|
19
|
+
- replace circular-json with flatted ([#23](https://github.com/royriojas/flat-cache/issues/23)) - [00f6892]( https://github.com/royriojas/flat-cache/commit/00f6892 ), [Terry](https://github.com/Terry), 05/11/2018 21:44:16
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
- **undefined**
|
|
23
|
+
- update del to v3.0.0 ([#26](https://github.com/royriojas/flat-cache/issues/26)) - [d42883f]( https://github.com/royriojas/flat-cache/commit/d42883f ), [Patrick Silva](https://github.com/Patrick Silva), 03/11/2018 03:00:44
|
|
24
|
+
|
|
25
|
+
Closes <a target="_blank" class="info-link" href="https://github.com/royriojas/flat-cache/issues/25"><span>#25</span></a>
|
|
26
|
+
## v1.3.0
|
|
27
|
+
- **Other changes**
|
|
28
|
+
- Added #all method ([#16](https://github.com/royriojas/flat-cache/issues/16)) - [12293be]( https://github.com/royriojas/flat-cache/commit/12293be ), [Ozair Patel](https://github.com/Ozair Patel), 25/09/2017 16:46:38
|
|
29
|
+
|
|
30
|
+
* Added #all method
|
|
31
|
+
|
|
32
|
+
* Added #all method test
|
|
33
|
+
|
|
34
|
+
* Updated readme
|
|
35
|
+
|
|
36
|
+
* Added yarn.lock
|
|
37
|
+
|
|
38
|
+
* Added more keys for #all test
|
|
39
|
+
|
|
40
|
+
* Beautified file
|
|
41
|
+
|
|
42
|
+
- fix changelog title style ([#14](https://github.com/royriojas/flat-cache/issues/14)) - [af8338a]( https://github.com/royriojas/flat-cache/commit/af8338a ), [前端小武](https://github.com/前端小武), 19/12/2016 23:34:48
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
## v1.2.2
|
|
46
|
+
- **Bug Fixes**
|
|
47
|
+
- Do not crash if cache file is invalid JSON. ([#13](https://github.com/royriojas/flat-cache/issues/13)) - [87beaa6]( https://github.com/royriojas/flat-cache/commit/87beaa6 ), [Roy Riojas](https://github.com/Roy Riojas), 19/12/2016 21:03:35
|
|
48
|
+
|
|
49
|
+
Fixes <a target="_blank" class="info-link" href="https://github.com/royriojas/flat-cache/issues/12"><span>#12</span></a>
|
|
50
|
+
|
|
51
|
+
Not sure under which situations a cache file might exist that does
|
|
52
|
+
not contain a valid JSON structure, but just in case to cover
|
|
53
|
+
the possibility of this happening a try catch block has been added
|
|
54
|
+
|
|
55
|
+
If the cache is somehow not valid the cache will be discarded an a
|
|
56
|
+
a new cache will be stored instead
|
|
57
|
+
- **Other changes**
|
|
58
|
+
- Added travis ci support for modern node versions ([#11](https://github.com/royriojas/flat-cache/issues/11)) - [1c2b1f7]( https://github.com/royriojas/flat-cache/commit/1c2b1f7 ), [Amila Welihinda](https://github.com/Amila Welihinda), 11/11/2016 02:47:52
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
- Bumping `circular-son` version ([#10](https://github.com/royriojas/flat-cache/issues/10)) - [4d5e861]( https://github.com/royriojas/flat-cache/commit/4d5e861 ), [Andrea Giammarchi](https://github.com/Andrea Giammarchi), 02/08/2016 09:13:52
|
|
62
|
+
|
|
63
|
+
As mentioned in https://github.com/WebReflection/circular-json/issues/25 `circular-json` wan't rightly implementing the license field.
|
|
64
|
+
|
|
65
|
+
Latest version bump changed only that bit so that ESLint should now be happy.
|
|
3
66
|
## v1.2.1
|
|
4
67
|
- **Bug Fixes**
|
|
5
68
|
- Add missing utils.js file to the package. closes [#8](https://github.com/royriojas/flat-cache/issues/8) - [ec10cf2]( https://github.com/royriojas/flat-cache/commit/ec10cf2 ), [Roy Riojas](https://github.com/Roy Riojas), 01/08/2016 04:18:57
|
|
@@ -10,7 +73,7 @@
|
|
|
10
73
|
- Add documentation about noPrune option - [23e11f9]( https://github.com/royriojas/flat-cache/commit/23e11f9 ), [Roy Riojas](https://github.com/Roy Riojas), 01/08/2016 04:06:49
|
|
11
74
|
|
|
12
75
|
|
|
13
|
-
## v1.0
|
|
76
|
+
## v1.1.0
|
|
14
77
|
- **Features**
|
|
15
78
|
- Add noPrune option to cache.save() method. closes [#7](https://github.com/royriojas/flat-cache/issues/7) - [2c8016a]( https://github.com/royriojas/flat-cache/commit/2c8016a ), [Roy Riojas](https://github.com/Roy Riojas), 01/08/2016 04:00:29
|
|
16
79
|
|
|
@@ -41,8 +104,6 @@
|
|
|
41
104
|
- travis tests on 0.12 and 4x - [3a613fd]( https://github.com/royriojas/flat-cache/commit/3a613fd ), [royriojas](https://github.com/royriojas), 15/11/2015 17:34:40
|
|
42
105
|
|
|
43
106
|
|
|
44
|
-
## v1.0.10
|
|
45
|
-
- **Build Scripts Changes**
|
|
46
107
|
- add eslint-fix task - [fd29e52]( https://github.com/royriojas/flat-cache/commit/fd29e52 ), [royriojas](https://github.com/royriojas), 01/11/2015 18:04:08
|
|
47
108
|
|
|
48
109
|
|
|
@@ -86,15 +147,79 @@
|
|
|
86
147
|
- Update dependencies - [be88aa3]( https://github.com/royriojas/flat-cache/commit/be88aa3 ), [Bogdan Chadkin](https://github.com/Bogdan Chadkin), 11/09/2015 15:47:41
|
|
87
148
|
|
|
88
149
|
|
|
89
|
-
## v1.0.
|
|
150
|
+
## v1.0.11
|
|
151
|
+
- **Features**
|
|
152
|
+
- Add noPrune option to cache.save() method. closes [#7](https://github.com/royriojas/flat-cache/issues/7) - [2c8016a]( https://github.com/royriojas/flat-cache/commit/2c8016a ), [Roy Riojas](https://github.com/Roy Riojas), 01/08/2016 04:00:29
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
- Add json read and write utility based on circular-json - [c31081e]( https://github.com/royriojas/flat-cache/commit/c31081e ), [Jean Ponchon](https://github.com/Jean Ponchon), 28/07/2016 10:58:17
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
- **Bug Fixes**
|
|
159
|
+
- Remove UTF16 BOM stripping - [4a41e22]( https://github.com/royriojas/flat-cache/commit/4a41e22 ), [Jean Ponchon](https://github.com/Jean Ponchon), 29/07/2016 04:18:06
|
|
160
|
+
|
|
161
|
+
Since we control both writing and reading of JSON stream, there no needs
|
|
162
|
+
to handle unicode BOM.
|
|
163
|
+
- Use circular-json to handle circular references (fix [#5](https://github.com/royriojas/flat-cache/issues/5)) - [cd7aeed]( https://github.com/royriojas/flat-cache/commit/cd7aeed ), [Jean Ponchon](https://github.com/Jean Ponchon), 25/07/2016 13:11:59
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
- **Tests Related fixes**
|
|
167
|
+
- Add missing file from eslint test - [d6fa3c3]( https://github.com/royriojas/flat-cache/commit/d6fa3c3 ), [Jean Ponchon](https://github.com/Jean Ponchon), 29/07/2016 04:15:51
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
- Add test for circular json serialization / deserialization - [07d2ddd]( https://github.com/royriojas/flat-cache/commit/07d2ddd ), [Jean Ponchon](https://github.com/Jean Ponchon), 28/07/2016 10:59:36
|
|
171
|
+
|
|
172
|
+
|
|
90
173
|
- **Refactoring**
|
|
91
|
-
-
|
|
174
|
+
- Remove unused read-json-sync - [2be1c24]( https://github.com/royriojas/flat-cache/commit/2be1c24 ), [Jean Ponchon](https://github.com/Jean Ponchon), 28/07/2016 10:59:18
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
- **Build Scripts Changes**
|
|
178
|
+
- travis tests on 0.12 and 4x - [3a613fd]( https://github.com/royriojas/flat-cache/commit/3a613fd ), [royriojas](https://github.com/royriojas), 15/11/2015 17:34:40
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
## v1.0.10
|
|
182
|
+
- **Build Scripts Changes**
|
|
183
|
+
- add eslint-fix task - [fd29e52]( https://github.com/royriojas/flat-cache/commit/fd29e52 ), [royriojas](https://github.com/royriojas), 01/11/2015 18:04:08
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
- make sure the test script also verify beautification and linting of files before running tests - [e94e176]( https://github.com/royriojas/flat-cache/commit/e94e176 ), [royriojas](https://github.com/royriojas), 01/11/2015 14:54:48
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
- test against node 4 - [c395b66]( https://github.com/royriojas/flat-cache/commit/c395b66 ), [royriojas](https://github.com/royriojas), 11/09/2015 17:51:39
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
- Add helpers/code check scripts - [bdb82f3]( https://github.com/royriojas/flat-cache/commit/bdb82f3 ), [royriojas](https://github.com/royriojas), 11/09/2015 16:44:31
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
- **Other changes**
|
|
196
|
+
- add clearAll for cacheDir - [97383d9]( https://github.com/royriojas/flat-cache/commit/97383d9 ), [xieyaowu](https://github.com/xieyaowu), 31/10/2015 23:02:18
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
- Move dependencies into devDep - [7e47099]( https://github.com/royriojas/flat-cache/commit/7e47099 ), [Bogdan Chadkin](https://github.com/Bogdan Chadkin), 11/09/2015 17:10:57
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
- Update dependencies - [be88aa3]( https://github.com/royriojas/flat-cache/commit/be88aa3 ), [Bogdan Chadkin](https://github.com/Bogdan Chadkin), 11/09/2015 15:47:41
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
- **Bug Fixes**
|
|
206
|
+
- wrong default values for changelogx user repo name - [7bb52d1]( https://github.com/royriojas/flat-cache/commit/7bb52d1 ), [royriojas](https://github.com/royriojas), 11/09/2015 17:59:30
|
|
92
207
|
|
|
93
208
|
|
|
94
209
|
- **Documentation**
|
|
210
|
+
- Add missing changelog link - [f51197a]( https://github.com/royriojas/flat-cache/commit/f51197a ), [royriojas](https://github.com/royriojas), 11/09/2015 16:48:05
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
- better description for the module - [436817f]( https://github.com/royriojas/flat-cache/commit/436817f ), [royriojas](https://github.com/royriojas), 11/09/2015 16:35:33
|
|
214
|
+
|
|
215
|
+
|
|
95
216
|
- Add documentation about `clearAll` and `clearCacheById` - [13947c1]( https://github.com/royriojas/flat-cache/commit/13947c1 ), [Roy Riojas](https://github.com/Roy Riojas), 02/03/2015 02:44:05
|
|
96
217
|
|
|
97
218
|
|
|
219
|
+
- **Refactoring**
|
|
220
|
+
- load a cache file using the full filepath - [b8f68c2]( https://github.com/royriojas/flat-cache/commit/b8f68c2 ), [Roy Riojas](https://github.com/Roy Riojas), 30/08/2015 06:19:14
|
|
221
|
+
|
|
222
|
+
|
|
98
223
|
- **Features**
|
|
99
224
|
- Add methods to remove the cache documents created - [af40443]( https://github.com/royriojas/flat-cache/commit/af40443 ), [Roy Riojas](https://github.com/Roy Riojas), 02/03/2015 02:39:27
|
|
100
225
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flat-cache",
|
|
3
|
-
"version": "1.2
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "A stupidly simple key/value storage using files to persist some data",
|
|
5
5
|
"repository": "royriojas/flat-cache",
|
|
6
6
|
"license": "MIT",
|
|
@@ -65,12 +65,12 @@
|
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"chai": "^3.2.0",
|
|
68
|
-
"changelogx": "
|
|
69
|
-
"esbeautifier": "
|
|
68
|
+
"changelogx": "3.0.0",
|
|
69
|
+
"esbeautifier": "10.1.1",
|
|
70
70
|
"eslinter": "^3.2.1",
|
|
71
|
-
"glob-expand": "
|
|
72
|
-
"istanbul": "
|
|
73
|
-
"mocha": "
|
|
71
|
+
"glob-expand": "0.2.1",
|
|
72
|
+
"istanbul": "0.4.5",
|
|
73
|
+
"mocha": "5.2.0",
|
|
74
74
|
"precommit": "^1.1.5",
|
|
75
75
|
"prepush": "^3.1.4",
|
|
76
76
|
"proxyquire": "^1.7.2",
|
|
@@ -79,8 +79,8 @@
|
|
|
79
79
|
"watch-run": "^1.2.2"
|
|
80
80
|
},
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"circular-json": "^0.3.
|
|
83
|
-
"del": "^
|
|
82
|
+
"circular-json": "^0.3.1",
|
|
83
|
+
"del": "^3.0.0",
|
|
84
84
|
"graceful-fs": "^4.1.2",
|
|
85
85
|
"write": "^0.2.1"
|
|
86
86
|
}
|
package/utils.js
CHANGED
|
@@ -4,6 +4,16 @@ var circularJson = require( 'circular-json' );
|
|
|
4
4
|
|
|
5
5
|
module.exports = {
|
|
6
6
|
|
|
7
|
+
tryParse: function ( filePath, defaultValue) {
|
|
8
|
+
var result;
|
|
9
|
+
try {
|
|
10
|
+
result = this.readJSON( filePath );
|
|
11
|
+
} catch (ex) {
|
|
12
|
+
result = defaultValue;
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
},
|
|
16
|
+
|
|
7
17
|
/**
|
|
8
18
|
* Read json file synchronously using circular-json
|
|
9
19
|
*
|