├── .gitignore ├── .npmignore ├── .travis.yml ├── CHANGELOG.md ├── README.md ├── api.md ├── dist ├── incache.js └── incache.min.js ├── examples ├── auto-load │ ├── app.js │ └── cache.json ├── auto-save │ ├── app-terminate.js │ └── app-timer.js ├── basic │ └── app.js ├── browser-auto-save │ └── index.html ├── browser-save │ └── index.html ├── load │ ├── app.js │ └── cache.json └── save │ └── app.js ├── extra └── logo.png ├── index.js ├── package.json ├── src ├── defined.js ├── helper.js └── incache.js ├── test ├── .incache-save ├── .incache-save2 ├── .incache-save5 ├── app │ ├── fake-content │ ├── index.js │ ├── middleware.js │ └── routes │ │ ├── hello.js │ │ └── index.js ├── helper.js ├── incache-auto-removed.js ├── incache-auto-save.js ├── incache-bulk.js ├── incache-clone.js ├── incache-delete-on-expires.js ├── incache-events.js ├── incache-exceeded.js ├── incache-hits.js ├── incache-info.js ├── incache-load-param.js ├── incache-manually.js ├── incache-more-instance.js ├── incache-no-share.js ├── incache-preserve.js ├── incache-record.js ├── incache-save-param.js ├── incache-save.js ├── incache-stats.js ├── incache.js ├── index.html ├── issues │ └── 4.js └── performace │ ├── load.js │ └── save.js ├── version-to-tag.sh └── webpack.config.js /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | node_modules/ -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | node_modules/ 3 | coverage/ 4 | extra/ 5 | test/ 6 | examples/ 7 | .travis.yml 8 | api.md 9 | version-to-tag.sh 10 | webpack.config.js -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "7" -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](http://keepachangelog.com/) 5 | and this project adheres to [Semantic Versioning](http://semver.org/). 6 | 7 | ## [7.2.1] - 2018-12-19 8 | - **Fixed** process don't exit if SAVE MODE is TIMER 9 | 10 | ## [7.2.0] - 2018-09-21 11 | - **Added** event `get` 12 | - **Added** event `beforeGet` 13 | 14 | ## [7.1.0] - 2018-09-20 15 | - **Added** method `info`, now it's possible retrieve only record info without increase `hits` 16 | 17 | ## [7.0.6] - 2018-09-19 18 | - **Removed** vulnerable library 19 | 20 | ## [7.0.5] - 2018-03-06 21 | - **Improved** `all` method, now can return also a plain object 22 | 23 | ## [7.0.4] - 2018-02-28 24 | - **Improved** `save` method, now create the full path if not exists 25 | 26 | ## [7.0.3] - 2018-02-24 27 | - **Improved** performance for `set` method 28 | 29 | ## [7.0.1] - 2018-02-19 30 | - **Fixed** empty `filePath` issue 31 | 32 | ## [7.0.0] - 2018-01-13 33 | - **Added** `load` support for browser 34 | - **Added** `save` support for browser 35 | - **Added** `autoLoad` support for browser 36 | - **Added** `autoSave` support for browser 37 | 38 | ## [6.6.1] - 2017-12-04 39 | - Fixed main entry point 40 | 41 | ## [6.6.0] - 2017-11-25 42 | - Added 43 | - methods 44 | - `suspendEvent` 45 | - `resumeEvent` 46 | - `suspendEvents` 47 | - `resumeEvents` 48 | 49 | ## [6.5.1] - 2017-11-19 50 | - Added 51 | - static method `isRecord` 52 | - UMD support 53 | - Changed 54 | - `bulkSet` now accepts custom array 55 | 56 | ## [6.4.0] - 2017-10-14 57 | - Improvement for `InCache` instance and `on` method, now are chainable 58 | - Added 59 | - events 60 | - `beforeLoad` 61 | - `beforeSave` 62 | - instance parameter to events 63 | - `load` 64 | - `save` 65 | - Bug fix 66 | 67 | ## [6.3.0] - 2017-09-30 68 | - Added 69 | - record property 70 | - `hits` 71 | - `lastHit` 72 | - `stats` method 73 | 74 | ## [6.2.0] - 2017-09-25 75 | - Added 76 | - path parameter to `load` and `save` methods, now it's possible specify a file path to load or save 77 | 78 | ## [6.1.1] - 2017-09-24 79 | - Typo fixed 80 | 81 | ## [6.1.0] - 2017-09-24 82 | - Added 83 | - events 84 | - `change` 85 | - `exceed` 86 | 87 | ## [6.0.0] - 2017-09-23 88 | - Added 89 | - options 90 | - `autoLoad` 91 | - `autoSave` 92 | - `autoSaveMode` 93 | - `autoSavePeriod` 94 | - `clone` 95 | - `preserve` 96 | - `deleteOnExpires` 97 | - `maxRecordNumber` 98 | - methods 99 | - `load()` 100 | - `save()` 101 | - `count()` 102 | - events 103 | - `load` 104 | - `save` 105 | 106 | ## [5.2.0] - 2017-09-06 107 | - **Important:** 108 | - changed the default value of `save` option, now is set to "false" 109 | - changed the default value of `share` option, now is set to "false" 110 | 111 | ## [5.1.0] - 2017-09-05 112 | - **Important:** changed the default value of `nullIfNotFound` option, now is set to "false" 113 | 114 | ## [5.0.0] - 2017-09-05 115 | - Added 116 | - method`on` 117 | - events: 118 | - `beforeSet` 119 | - `set` 120 | - `create` 121 | - `update` 122 | - `beforeRemove` 123 | - `remove` 124 | - `beforeBulkSet` 125 | - `bulkSet` 126 | - `beforeBulkRemove` 127 | - `bulkRemove` 128 | - `expired` 129 | - options: 130 | - `autoRemovePeriod`, now InCache can remove automatically expired records without calling any methods 131 | - `nullIfNotFound` 132 | - Deprecated methods: 133 | - `onCreated` 134 | - `onUpdated` 135 | - `onRemoved` 136 | 137 | ## [4.2.1] - 2017-09-01 138 | - Fixed wrong warning message 139 | 140 | ## [4.2.0] - 2017-09-01 141 | - Added new property to configuration: `share`, now is possible disable global storage 142 | 143 | ## [4.1.2] - 2017-08-30 144 | - Fixed `record.createdOn` is null, it happened when record was updated 145 | 146 | ## [4.1.1] - 2017-08-30 147 | - Added `destroy`, alias of `remove` 148 | - Removed unused code 149 | 150 | ## [4.1.0] - 2017-08-29 151 | - Added new method: `removeExpired`, now is possible remove all records expired at once 152 | 153 | ## [4.0.2] - 2017-08-22 154 | - Fixed expires: now if set overwrites maxAge 155 | 156 | ## [4.0.1] - 2017-08-22 157 | - Fixed default configuration 158 | 159 | ## [4.0.0] - 2017-08-22 160 | - Changed configuration 161 | - Added new properties 162 | - `maxAge` 163 | - `expires` 164 | - `silent` 165 | - **Deprecated properties** 166 | - `global.life` 167 | - `global.silent` 168 | 169 | ## [3.1.1] - 2017-08-21 170 | - Fixed readme 171 | 172 | ## [3.1.0] - 2017-08-21 173 | - Added `clean` method 174 | 175 | ## [3.0.1] - 2017-08-20 176 | - Removed unnecessary files for deployment on NPM 177 | 178 | ## [3.0.0] - 2017-08-19 179 | - Library loading was changed: 180 | - **Now you need to instantiate the `new InCache` object** 181 | - Added cache writing to disk 182 | - Added `setConfig` method 183 | - Added `addTo` method 184 | - Added `prependTo` method 185 | - Added `updateIn` method 186 | - Added `removeFrom` method 187 | - Added global record configuration 188 | 189 | ## [2.0.0] - 2017-08-13 190 | - Changed `set` method: last argument now is an object, see documentation. 191 | - Added expiry date 192 | 193 | ## [1.0.1] - 2017-08-12 194 | - First release -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
Promise
24 | * [.save([path])](#InCache+save) ⇒ Promise
25 | * [.setConfig([opts])](#InCache+setConfig)
26 | * [.getConfig()](#InCache+getConfig) ⇒ \*
27 | * [.set(key, value, [opts])](#InCache+set) ⇒ [record
](#InCache..record) \| \*
28 | * [.get(key, [onlyValue])](#InCache+get) ⇒ [record
](#InCache..record) \| \*
\| null
\| undefined
29 | * [.info(key)](#InCache+info) ⇒ [recordInfo
](#InCache..recordInfo) \| \*
\| undefined
30 | * [.remove(key, [silent])](#InCache+remove)
31 | * [.removeFrom(key, where)](#InCache+removeFrom)
32 | * [.removeExpired()](#InCache+removeExpired) ⇒ Array
33 | * [.addTo(key, value)](#InCache+addTo) ⇒ [record
](#InCache..record) \| undefined
34 | * [.prependTo(key, value)](#InCache+prependTo) ⇒ [record
](#InCache..record) \| undefined
35 | * [.updateIn(key, value, where)](#InCache+updateIn)
36 | * [.bulkSet(records, [silent])](#InCache+bulkSet) ⇒ Object
\| undefined
37 | * [.bulkRemove(keys, [silent])](#InCache+bulkRemove)
38 | * [.clean(key)](#InCache+clean)
39 | * [.all(asObject)](#InCache+all) ⇒ \*
40 | * [.count()](#InCache+count) ⇒ Number
41 | * [.expired(key)](#InCache+expired) ⇒ boolean
42 | * [.clear()](#InCache+clear)
43 | * [.has(key)](#InCache+has) ⇒ boolean
44 | * [.destroy(...args)](#InCache+destroy)
45 | * [.stats()](#InCache+stats) ⇒ Object
46 | * [.canBeAutoRemove(key)](#InCache+canBeAutoRemove) ⇒ boolean
\| \*
47 | * boolean
71 | * _inner_
72 | * [~record](#InCache..record) : Object
73 | * [~recordInfo](#InCache..recordInfo) : Object
74 | * function
function
function
Param | Type | Default | Description | 87 |
---|---|---|---|
[opts] | Object | configuration object 92 | |
93 | |
[opts.maxAge] | number | 0 | max age in milliseconds. If 0 not expire. (overwritable by |
96 |
[opts.expires] | Date | string | a Date for expiration. (overwrites |
99 | |
[opts.silent] | boolean | false | if true no event will be triggered. (overwritable by |
102 |
[opts.deleteOnExpires] | boolean | true | if false, the record will not be deleted after expiry. (overwritable by |
105 |
[opts.clone] | boolean | false | if true, the object will be cloned before to put it in storage. (overwritable by |
108 |
[opts.preserve] | boolean | false | if true, you will no longer be able to update the record once created. (overwritable by |
111 |
[opts.maxRecordNumber] | number | 0 | the maximum of record number of the cache, if exceeded some records will be deleted. If 0 is disabled 113 | |
114 |
[opts.autoLoad] | boolean | true | load cache from disk when instance is created. 116 | |
117 |
[opts.autoSave] | boolean | false | if true saves cache in disk when the process is terminated. 119 | |
120 |
[opts.autoSaveMode] | string | "terminate" | there are 2 modes -> "terminate": saves before the process is terminated (server only). "timer": every n seconds checks for new changes and save on disk. 122 | |
123 |
[opts.autoSavePeriod] | number | 5 | period in seconds to check for new changes to save on disk. Works only if |
126 |
[opts.filePath] | string | * | ".incache" | cache file path or key. If is a falsy value, |
129 |
[opts.storeName] | string | store name 131 | |
132 | |
[opts.share] | boolean | false | if true, use global object as storage 134 | |
135 |
[opts.autoRemovePeriod] | number | 0 | period in seconds to remove expired records. When set, the records will be removed only on check, when 0 it won't run 137 | |
138 |
[opts.nullIfNotFound] | boolean | false | calling |
141 |
[opts.save] | boolean | false | deprecated: if true saves cache in disk when the process is terminated. Use |
144 |
[opts.global] | Object | deprecated: global record configuration 146 | |
147 | |
[opts.global.silent] | boolean | false | deprecated: if true no event will be triggered, use |
150 |
[opts.global.life] | number | 0 | deprecated: max age in seconds. If 0 not expire, use |
153 |
Promise
159 | Load cache from disk
160 |
161 | **Kind**: instance method of [InCache
](#InCache)
162 | **Emits**: [beforeLoad
](#InCache+event_beforeLoad), [load
](#InCache+event_load)
163 | **Since**: 6.0.0
164 | Param | Type | Default | Description | 168 |
---|---|---|---|
[path] | string | "opts.filePath" | file path or key (browser scenario) 173 | |
174 |
Promise
180 | Save cache into disk
181 |
182 | **Kind**: instance method of [InCache
](#InCache)
183 | **Emits**: [beforeSave
](#InCache+event_beforeSave), [save
](#InCache+event_save)
184 | **Since**: 6.0.0
185 | Param | Type | Default | Description | 189 |
---|---|---|---|
[path] | string | "opts.filePath" | file path or key (browser scenario) 194 | |
195 |
InCache
](#InCache)
204 | **See**: [constructor](constructor) for further information
205 | **Since**: 3.0.0
206 | Param | Type | Description | 210 |
---|---|---|
[opts] | Object | configuration object 215 | |
216 |
\*
222 | Get configuration
223 |
224 | **Kind**: instance method of [InCache
](#InCache)
225 |
226 |
227 | ### inCache.set(key, value, [opts]) ⇒ [record
](#InCache..record) \| \*
228 | Set/update record
229 |
230 | **Kind**: instance method of [InCache
](#InCache)
231 | **Emits**: [beforeSet
](#InCache+event_beforeSet), [create
](#InCache+event_create), [update
](#InCache+event_update), [set
](#InCache+event_set)
232 | Param | Type | Default | Description | 236 |
---|---|---|---|
key | string | 241 | | |
value | * | 243 | | |
[opts] | Object | options object 245 | |
246 | |
[opts.silent] | boolean | false | if true no event will be triggered. (overwrites global configuration) 248 | |
249 |
[opts.maxAge] | number | 0 | max age in milliseconds. If 0 not expire. (overwrites global configuration) 251 | |
252 |
[opts.clone] | boolean | false | if true, the object will be cloned before to put it in storage. (overwrites global configuration) 254 | |
255 |
[opts.preserve] | boolean | false | if true, you will no longer be able to update the record once created. (overwrites global configuration) 257 | |
258 |
[opts.expires] | Date | string | a Date for expiration. (overwrites global configuration and |
261 | |
[opts.deleteOnExpires] | boolean | true | if false, the record will not be deleted after expiry. (overwrites global configuration) 263 | |
264 |
[opts.life] | number | 0 | deprecated: max age in seconds. If 0 not expire. (overwrites global configuration) 266 | |
267 |
record
](#InCache..record) \| \*
\| null
\| undefined
277 | Get record by key
278 |
279 | **Kind**: instance method of [InCache
](#InCache)
280 | **Emits**: [get
](#InCache+event_get), [beforeGet
](#InCache+event_beforeGet)
281 | Param | Type | Default | Description | 285 |
---|---|---|---|
key | string | 290 | | |
[onlyValue] | boolean | true | if false get InCache record 292 | |
293 |
recordInfo
](#InCache..recordInfo) \| \*
\| undefined
303 | Get info record by key
304 |
305 | **Kind**: instance method of [InCache
](#InCache)
306 | **Since**: 7.1.0
307 | Param | Type | 311 |
---|---|
key | string |
316 |
InCache
](#InCache)
329 | **Emits**: [beforeRemove
](#InCache+event_beforeRemove), [remove
](#InCache+event_remove)
330 | Param | Type | Default | Description | 334 |
---|---|---|---|
key | string | 339 | | |
[silent] | boolean | false | if true no event will be triggered 341 | |
342 |
InCache
](#InCache)
355 | **Since**: 3.0.0
356 | Param | Type | 360 |
---|---|
key | string |
365 |
where | * |
367 |
Array
377 | Remove expired records
378 |
379 | **Kind**: instance method of [InCache
](#InCache)
380 | **Returns**: Array
- expired keys
381 | **Since**: 4.1.0
382 | **Example**
383 | ```js
384 | inCache.set('my key 1', 'my value');
inCache.set('my key 2', 'my value', {maxAge: 1000});
inCache.set('my key 3', 'my value', {maxAge: 1500});
setTimeout(()=>{
inCache.removeExpired();
inCache.all(); //-> [{key: 'my key 1', value: 'my value'}]
}, 2000)
385 | ```
386 |
387 |
388 | ### inCache.addTo(key, value) ⇒ [record
](#InCache..record) \| undefined
389 | Given a key that has value like an array adds value to end of array
390 |
391 | **Kind**: instance method of [InCache
](#InCache)
392 | **Since**: 3.0.0
393 | Param | Type | 397 |
---|---|
key | string |
402 |
value | * |
404 |
record
](#InCache..record) \| undefined
414 | Given a key that has value like an array adds value to beginning of array
415 |
416 | **Kind**: instance method of [InCache
](#InCache)
417 | **Since**: 3.0.0
418 | Param | Type | 422 |
---|---|
key | string |
427 |
value | * |
429 |
InCache
](#InCache)
442 | **Since**: 3.0.0
443 | Param | Type | 447 |
---|---|
key | string |
452 |
value | * |
454 |
where | * |
456 |
Object
\| undefined
466 | Set/update multiple records. This method not trigger any event.
467 |
468 | **Kind**: instance method of [InCache
](#InCache)
469 | **Emits**: [beforeBulkSet
](#InCache+event_beforeBulkSet), [bulkSet
](#InCache+event_bulkSet)
470 | Param | Type | Default | Description | 474 |
---|---|---|---|
records | Array | e.g. [{key: foo1, value: bar1},{key: foo2, value: bar2}] 479 | |
480 | |
[silent] | boolean | false | if true no event will be triggered 482 | |
483 |
InCache
](#InCache)
496 | **Emits**: [beforeBulkRemove
](#InCache+event_beforeBulkRemove), [bulkRemove
](#InCache+event_bulkRemove)
497 | Param | Type | Default | Description | 501 |
---|---|---|---|
keys | Array | an array of keys 506 | |
507 | |
[silent] | boolean | false | if true no event will be triggered 509 | |
510 |
InCache
](#InCache)
523 | Param | Type | Description | 527 |
---|---|---|
key | string | a string that is relative to a group of keys 532 | |
533 |
\*
543 | Fetch all records
544 |
545 | **Kind**: instance method of [InCache
](#InCache)
546 | Param | Default | 550 |
---|---|
asObject | false |
555 |
Number
561 | Returns total of records in storage
562 |
563 | **Kind**: instance method of [InCache
](#InCache)
564 | **Since**: 6.0.0
565 |
566 |
567 | ### inCache.expired(key) ⇒ boolean
568 | Check if record is expired
569 |
570 | **Kind**: instance method of [InCache
](#InCache)
571 | Param | Type | 575 |
---|---|
key | string |
580 |
InCache
](#InCache)
589 |
590 |
591 | ### inCache.has(key) ⇒ boolean
592 | Check if key exists
593 |
594 | **Kind**: instance method of [InCache
](#InCache)
595 | Param | Type | 599 |
---|---|
key | string |
604 |
InCache
](#InCache)
617 | **Since**: 4.1.1
618 | Param | 622 |
---|
...args | 627 |
Object
633 | Returns stats of storage
634 |
635 | **Kind**: instance method of [InCache
](#InCache)
636 | **Since**: 6.3.0
637 |
638 |
639 | ### inCache.canBeAutoRemove(key) ⇒ boolean
\| \*
640 | Check if key can be auto removed
641 |
642 | **Kind**: instance method of [InCache
](#InCache)
643 | Param | 647 |
---|
key | 652 |
InCache
](#InCache)
663 | Param | Type | Description | 667 |
---|---|---|
callback | removedCallback | callback function 672 | |
673 |
InCache
](#InCache)
688 | Param | Type | Description | 692 |
---|---|---|
callback | createdCallback | callback function 697 | |
698 |
InCache
](#InCache)
713 | Param | Type | Description | 717 |
---|---|---|
callback | updatedCallback | callback function 722 | |
723 |
InCache
](#InCache)
736 | **Since**: 7.2.0
737 | Param | Type | Description | 741 |
---|---|---|
key | string | key 746 | |
747 |
record | record | record object 749 | |
750 |
InCache
](#InCache)
759 | **Since**: 7.2.0
760 | Param | Type | Description | 764 |
---|---|---|
key | string | key 769 | |
770 |
record | record | record object 772 | |
773 |
InCache
](#InCache)
782 | **Since**: 5.0.0
783 | Param | Type | Description | 787 |
---|---|---|
key | string | key 792 | |
793 |
value | string | value 795 | |
796 |
InCache
](#InCache)
805 | **Since**: 5.0.0
806 | Param | Type | Description | 810 |
---|---|---|
key | string | key 815 | |
816 |
record | record | record object 818 | |
819 |
InCache
](#InCache)
828 | **Since**: 5.0.0
829 | Param | Type | Description | 833 |
---|---|---|
key | string | key of record 838 | |
839 |
record | record | record object 841 | |
842 |
InCache
](#InCache)
851 | **Since**: 5.0.0
852 | Param | Type | Description | 856 |
---|---|---|
key | string | key of record 861 | |
862 |
record | record | record object 864 | |
865 |
InCache
](#InCache)
874 | **Since**: 5.0.0
875 | Param | Type | Description | 879 |
---|---|---|
key | string | key of record to be removed 884 | |
885 |
InCache
](#InCache)
894 | **Since**: 5.0.0
895 | Param | Type | Description | 899 |
---|---|---|
key | string | key of record 904 | |
905 |
InCache
](#InCache)
914 | **Since**: 5.0.0
915 | Param | Type | Description | 919 |
---|---|---|
records | Array | array of objects 924 | |
925 |
InCache
](#InCache)
934 | **Since**: 5.0.0
935 | Param | Type | Description | 939 |
---|---|---|
records | Array | array of objects 944 | |
945 |
InCache
](#InCache)
954 | **Since**: 5.0.0
955 | Param | Type | Description | 959 |
---|---|---|
keys | Array | array of keys to be removed 964 | |
965 |
InCache
](#InCache)
974 | **Since**: 5.0.0
975 | Param | Type | Description | 979 |
---|---|---|
keys | Array | array of keys removed 984 | |
985 |
InCache
](#InCache)
994 | **Since**: 5.0.0
995 | Param | Type | Description | 999 |
---|---|---|
keys | Array | array of keys expired 1004 | |
1005 |
InCache
](#InCache)
1014 | **Since**: 6.4.0
1015 | Param | Type | 1019 |
---|---|
me | InCache |
1024 |
InCache
](#InCache)
1033 | **Since**: 6.0.0
1034 | Param | Type | Description | 1038 |
---|---|---|
err | null | string | error message, if no errors occurred is null 1043 | |
1044 |
me | InCache | 1046 | |
InCache
](#InCache)
1055 | **Since**: 6.4.0
1056 | Param | Type | 1060 |
---|---|
me | InCache |
1065 |
InCache
](#InCache)
1074 | **Since**: 6.0.0
1075 | Param | Type | Description | 1079 |
---|---|---|
err | null | string | error message, if no errors occurred is null 1084 | |
1085 |
me | InCache | 1087 | |
InCache
](#InCache)
1096 | **Since**: 6.1.0
1097 | Param | Type | Description | 1101 |
---|---|---|
by | string | event called by |
1107 |
InCache
](#InCache)
1116 | **Since**: 6.1.0
1117 | Param | Type | Description | 1121 |
---|---|---|
diff | number | exceeded by record number 1126 | |
1127 |
boolean
1133 | Check if object is a InCache~record
1134 |
1135 | **Kind**: static method of [InCache
](#InCache)
1136 | Param | Type | Description | 1140 |
---|---|---|
obj | record | InCache record 1145 | |
1146 |
Object
1152 | InCache record
1153 |
1154 | **Kind**: inner typedef of [InCache
](#InCache)
1155 | **Properties**
1156 |
1157 | Name | Type | Description | 1161 |
---|---|---|
id | string | uuid 1166 | |
1167 |
isNew | boolean | indicates if is a new record 1169 | |
1170 |
isPreserved | boolean | indicates if record will no longer be editable once created 1172 | |
1173 |
toDelete | boolean | indicates if record will be deleted after expiry 1175 | |
1176 |
hits | number | how many times it has been used 1178 | |
1179 |
lastHit | Date | null | last usage 1181 | |
1182 |
createdOn | Date | null | creation date 1184 | |
1185 |
updatedOn | Date | null | update date 1187 | |
1188 |
expiresOn | Date | null | expiry date 1190 | |
1191 |
value | * | record value 1193 | |
1194 |
Object
1200 | InCache recordInfo
1201 |
1202 | **Kind**: inner typedef of [InCache
](#InCache)
1203 | **Properties**
1204 |
1205 | Name | Type | Description | 1209 |
---|---|---|
id | string | uuid 1214 | |
1215 |
isNew | boolean | indicates if is a new record 1217 | |
1218 |
isPreserved | boolean | indicates if record will no longer be editable once created 1220 | |
1221 |
toDelete | boolean | indicates if record will be deleted after expiry 1223 | |
1224 |
hits | number | how many times it has been used 1226 | |
1227 |
lastHit | Date | null | last usage 1229 | |
1230 |
createdOn | Date | null | creation date 1232 | |
1233 |
updatedOn | Date | null | update date 1235 | |
1236 |
expiresOn | Date | null | expiry date 1238 | |
1239 |
function
InCache
](#InCache)
1250 | Param | Type | Description | 1254 |
---|---|---|
key | string | key of record removed 1259 | |
1260 |
function
InCache
](#InCache)
1271 | Param | Type | Description | 1275 |
---|---|---|
key | string | key of record created 1280 | |
1281 |
record | record | record object 1283 | |
1284 |
function
InCache
](#InCache)
1295 | Param | Type | Description | 1299 |
---|---|---|
key | string | key of record updated 1304 | |
1305 |
record | record | record object 1307 | |
1308 |
SAVE_MODE
](#SAVE_MODE)
1324 |
1325 |
1326 | ### SAVE_MODE.TIMER
1327 | **Kind**: static property of [SAVE_MODE
](#SAVE_MODE)
1328 |
--------------------------------------------------------------------------------
/examples/auto-load/app.js:
--------------------------------------------------------------------------------
1 | const InCache = require('../../src/incache');
2 |
3 | new InCache({
4 | autoLoad: true,
5 | filePath: 'cache.json'
6 | }).on('load', (err, me) => {
7 | if(!err)
8 | console.log('load', me.get('a key'));
9 | });
--------------------------------------------------------------------------------
/examples/auto-load/cache.json:
--------------------------------------------------------------------------------
1 | {"a key":{"id":"034953b0-b057-11e7-818a-5798d0166a8f","isNew":false,"isPreserved":false,"toDelete":true,"hits":2,"lastHit":"2017-10-13T20:54:51.060Z","createdOn":"2017-10-13T20:42:22.187Z","updatedOn":"2017-10-13T20:54:51.045Z","expiresOn":null,"value":"a value"}}
--------------------------------------------------------------------------------
/examples/auto-save/app-terminate.js:
--------------------------------------------------------------------------------
1 | const InCache = require('../../src/incache');
2 |
3 | const store = new InCache({
4 | autoSave: true,
5 | autoSaveMode: InCache.SAVE_MODE.TERMINATE,
6 | filePath: 'cache-terminate.json'
7 | });
8 |
9 | store.set('a key', 'a value');
10 |
11 | console.log(store.get('a key'));
--------------------------------------------------------------------------------
/examples/auto-save/app-timer.js:
--------------------------------------------------------------------------------
1 | const InCache = require('../../src/incache');
2 |
3 | const store = new InCache({
4 | autoSave: true,
5 | autoSaveMode: InCache.SAVE_MODE.TIMER,
6 | filePath: 'cache-timer.json'
7 | }).on('beforeSave', () => {
8 | console.log('before save');
9 | }).on('save', () => {
10 | console.log('save');
11 | });
12 |
13 | store.set('a key', 'a value');
14 |
15 | console.log(store.get('a key'));
--------------------------------------------------------------------------------
/examples/basic/app.js:
--------------------------------------------------------------------------------
1 | const InCache = require('../../src/incache');
2 |
3 | const store = new InCache();
4 |
5 | store.set('a key', 'a value');
6 |
7 | console.log(store.get('a key'));
--------------------------------------------------------------------------------
/examples/browser-auto-save/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |