What does?
InCache is a module that store any info in memory, it can be used for example for storing server sessions, caching http response or sharing singleton object in your apps. It also give you the possibility to save data on disk so you can avoid the data loss when the process exit or restart. In a browser scenario all data is saved on localStorage through a key.
Installation
Node.js
npm install incache --save
Examples
Basic
const InCache = ;const store = ; // Create a record with key 'my key'store; // Update 'my key'store; // Get keystore; // Remove 'my key'store; // Clearstoreclear; // Expires after 2 secondsstore;// Or expires on...store;
Auto remove expired records
const store = autoRemovePeriod: 2 //checks every 2 seconds; store; ;
Max cache size
const store = maxRecordNumber: 5; store;store;store;store;store;store; console; //=> 5console; //=> false
Load manually
const store = autoLoad: false; // This method returns a Promisestore;
Save on disk
By default this operation is running before the process is terminated
const store = autoSave: true;
Save when data is changed
const store = autoSave: true autoSaveMode: 'timer';
Save manually
const store = filePath: 'my-path/my-store.json'; store; // This method returns a Promisestore; // or specify a pathstore;
Browser scenario
In browser environment the file path becomes a string key for localStorage interface:
store;store;
Events
// Triggered when a record has been deletedincache; // Triggered before create/updateincache; // Triggered when a record has been createdincache; //Triggered when a record has been updatedincache; //Triggered when the cache is saved on diskincache; //Triggered when the cache exceed max sizeincache; //... for more events see the documentation
API
Please see the full documentation for more details.
Browser
Local
CDN unpkg
CDN jsDeliver
Changelog
You can view the changelog here
License
InCache is open-sourced software licensed under the MIT license