A simple file-based cache implementation using Node.js
npm install https://github.com/18Miguel/file-cache
const FileCache = require('file-cache');
// Create a new instance of FileCache
const cache = new FileCache();
// Set a value in the cache
cache.set('key', 'value');
// Get a value from the cache
console.log(cache.get('key')); // Output: value
// Remove a value from the cache
cache.delete('key');
// Clear the entire cache
cache.clear();
Creates an instance of FileCache.
filename
(optional): Custom filename for the cache. If not provided, a default filename will be generated.filepath
(optional): Custom file path for the cache. If not provided, a default file path will be set (system temp directory).
Checks if the cache contains a value for the given key.
key
: The cache key to check.- Returns: true if the cache has a value for the key, false otherwise.
Sets a value in the cache for the given key.
key
: The cache key.value
: The value to be cached.
Retrieves a value from the cache for the given key.
key
: The cache key.- Returns: The cached value.
Retrieves and removes the value from the cache for the given key.
key
: The cache key.- Returns: The cached value.
Removes the value from the cache for the given key.
key
: The cache key.
Clears the cache by removing all key-value pairs.
This project is licensed under the MIT License - see the LICENSE file for details.