Cache
Cache provides caching functionality, which can be used to cache the results of complex computations.
Usage
You need to import @giteeteam/apps-api
import { Cache } from '@giteeteam/apps-api';
const run = async () => {
const myCache = new Cache({
ttl: 3600 * 1000, // ttl in milliseconds, default is 1 minute
})
// Set cache
await myCache.set('cache-key', 'cache-value');
// You can set ttl separately
await myCache.set('cache-key', 'cache-value', { ttl: 60 * 1000 })
// Get cache
await myCache.get('cache-key');
// Delete cache
await myCache.del('cache-key');
// Increment the numeric value stored in the key by one
await myCache.incr('cache-key');
// Increment the value stored in the key by the given increment
await myCache.incrby('cache-key', 10);
// Decrement the numeric value stored in the key by one
await myCache.decr('cache-key');
// Decrement the value stored in the key by the given decrement
await myCache.decrby('cache-key', 10);
// Define a Lua script command
await myCache.defineCommand("command-name", {
lua: "..........define Lua script"
});
// Execute the previously defined Lua script
await myCache.execCommand("command-name", [arg1, arg2, arg3]);
}