system-cache
Version:
use cache with this simple helper
98 lines (71 loc) • 2.26 kB
Markdown
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 mordekayh in your project
```
npm install system-cache
```
```JavaScript
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"}});
```
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.
Save cache
```javascript
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
```
* **KeigoCode** - *Developer* - [Github](https://github.com/KeigoCode)
* **Kan014** - *Developer* - [Github](https://github.com/kan014)
This project is an extension to the open source clayber.
---
⌨️ with ❤️ by [KeigoCode](https://github.com/keigocode) 😊
⌨️ with ❤️ by [Kan014](https://github.com/kan014) 😊