mini-cache-ttl
v1.2.5
Published
To install the `mini-cache-ttl` package, use the following command:
Readme
mini-cache-ttl
Installation
To install the mini-cache-ttl package, use the following command:
npm install mini-cache-ttlUsage
You can use the mini-cache-ttl package in the following ways:
- Global Store:
import cache from 'mini-cache-ttl';
cache.set('key', 'value', 60); // Set a value with a TTL of 60 seconds
const value = cache.get('key'); // Get the value- Custom Stores:
import { createStore } from 'mini-cache-ttl';
const store = createStore();
store.set('key', 'value', 60);
const value = store.get('key');- Express Session Store:
import { expressSessionStore } from 'mini-cache-ttl';
const MiniCacheSessionStore = await expressSessionStore();
// Use MiniCacheSessionStore as the session store in your Express appAPI
The mini-cache-ttl package provides the following API:
cache.get(key): Retrieve the value for the givenkey.cache.set(key, value, ttlSec): Set a value for the givenkeywith an optional Time-To-Live (TTL) in seconds.cache.update(key, value, ttlSec): Update the value and/or TTL for the givenkey.cache.rename(oldKey, newKey): Rename theoldKeytonewKey.cache.del(key): Delete the value for the givenkey.cache.keys(): Get an array of all valid keys.cache.clear(): Clear the entire cache.cache.size(): Get the number of valid keys in the cache.cache.touch(key, ttlSec): Extend the TTL for the givenkey.cache.has(key): Check if the givenkeyexists in the cache.createStore(): Create a new custom cache store.expressSessionStore(options): Create an adapter for theexpress-sessionpackage.
Contributing
Contributions to the mini-cache-ttl project are welcome. Please follow the standard GitHub workflow:
- Fork the repository
- Create a new branch for your feature or bug fix
- Implement your changes
- Submit a pull request
License
The mini-cache-ttl package is licensed under the MIT License.
