1.0.2 • Published 3 years ago
another-cache v1.0.2
Installation 🔧
npm install another-cache
Example 📄
import CacheManager from "another-cache";
const cache = new CacheManager(cacheDirectory?: string); // Here you can define a directory to store your cache as JSON files.
cache.onExpired.subscribe((cacheData) => {
console.log("[TIMEOUT] " + cacheData.key + " / " + cacheData.timeout);
});
cache.set("test", {test: 0}, 5000);
const data = cache.get("test");
console.log(data);
Functions 📗
Set an item with a key in the cache. You can set a timeout in ms.
cache.set(key: string, value: any, timeoutMs?: number);
Get an item with the key from the cache.
cache.get(key: string);
Delete an item with the key from the cache.
cache.delete(key: string);
Gives you the expiration date of the item in the cache.
cache.getExpire(key: string);
Gives you the expiration state of the item in the cache.
cache.isExpired(key: string);
Delete all items from the cache.
cache.clear();
Get a list with all keys in the cache.
cache.keys();
License 📑
This code is available under the Mozilla Public License Version 2.0.