Skip to content

A simple file-based cache implementation using Node.js.

License

Notifications You must be signed in to change notification settings

18Miguel/file-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

File Cache

A simple file-based cache implementation using Node.js Miguel-NodeJS

Installation

npm install https://github.com/18Miguel/file-cache

Usage

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();

API

new FileCache(filename)

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).

cache.has(key)

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.

cache.set(key, value)

Sets a value in the cache for the given key.

  • key: The cache key.
  • value: The value to be cached.

cache.get(key)

Retrieves a value from the cache for the given key.

  • key: The cache key.
  • Returns: The cached value.

cache.take(key)

Retrieves and removes the value from the cache for the given key.

  • key: The cache key.
  • Returns: The cached value.

cache.delete(key)

Removes the value from the cache for the given key.

  • key: The cache key.

cache.clear()

Clears the cache by removing all key-value pairs.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A simple file-based cache implementation using Node.js.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published