system-cache
v1.0.3
Published
use cache with this simple helper
Downloads
4
Maintainers
Readme
Cache helper
use this little helper to cache memory, this works for databases, request. Avoid processing a machine with only the cache. That each request that is made, it is much faster to do it. With a little practice you can achieve a lot.
Install
install mordekayh in your project
npm install system-cache
Usage
const cache = require('system-cache');
const helper = new cache();
const database = new DB();
helper.setOptions({
async: true,
regist: true,
execFunction: async () => {
return database.get('hello')
}
})
helper.setCache({title: {title: "a", text: "a"}});
Options
Use this function to add or edit your cache manager options.
**async: ** when executing a request to the cache, this will execute the function, asynchronous or synchronous **regist: ** prevents an option from being wrongly saved with this parameter. **execFunction: ** This option will be executed when you ask with the getCache function.
Using and Get Cache
Save cache
const cache = require('system-cache');
const helper = new cache();
// SET OPTIONS
helper.setOptions({
async: true,
regist: true,
// THIS FUNCTION IS RUN WHEN GETCACHE IS CALLED
execFunction: async () => {
return database.get('hello')
}
})
// ADD CACHE
helper.setCache({title: {title: "a", text: "a"}});
// GET CACHE
helper.getCache(async (data) => {
console.log(data)
})
// CLEAR HISTORY CACHE
helper.clearCache();
// RESET CACHE
helper.resetCache();
// ENCRYPT
helper.encrypt(args);
// CHECK THE CHILDS OF THE OBJECT
helper.child('example');
helper.child('example').child('example');
helper.child('example').child('example').parent();
// GET WITH AWAIT
(async () => {
const data = await helper.getCache((s) => s);
console.log(data);
})
// CLEAR CACHE
Developers
Information
This project is an extension to the open source clayber.