https://github.com/uzo-felix/cache-wizard
🚧 Work in Progress 🚧 A middleware library for caching data with various eviction policies, cache invalidation, and cache coherency strategies.
https://github.com/uzo-felix/cache-wizard
cache-coherency cache-eviction-policy cache-invalidation cache-middleware cache-storage caching nodejs
Last synced: 2 months ago
JSON representation
🚧 Work in Progress 🚧 A middleware library for caching data with various eviction policies, cache invalidation, and cache coherency strategies.
- Host: GitHub
- URL: https://github.com/uzo-felix/cache-wizard
- Owner: Uzo-Felix
- License: mit
- Created: 2024-02-01T10:42:17.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-03T08:43:03.000Z (over 1 year ago)
- Last Synced: 2025-01-23T21:17:07.026Z (4 months ago)
- Topics: cache-coherency, cache-eviction-policy, cache-invalidation, cache-middleware, cache-storage, caching, nodejs
- Language: JavaScript
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: docs/README.md
- License: LICENSE
Awesome Lists containing this project
README
# Cache-wizard
Cache-wizard is a JavaScript library that provides middleware for caching data with various eviction policies, cache invalidation, and cache coherency strategies.
## Installation
You can install Cache-wizard via npm:
```bash
npm install Cache-wizard## Usage
Here's a basic example of how to use Cache-wizard:
```javascript
const { CacheMiddleware } = require('Cache-wizard');// Create a cache middleware instance
const cache = new CacheMiddleware();// Set key-value pairs in the cache
cache.set('key1', 'value1');
cache.set('key2', 'value2');// Retrieve values from the cache
console.log(cache.get('key1')); // Output: value1
console.log(cache.get('key2')); // Output: value2// Invalidate a key in the cache
cache.invalidate('key1');// Retrieve the invalidated key (should return null)
console.log(cache.get('key1')); // Output: null// Clear the entire cache
cache.clear();
```For more advanced usage and configurations, please refer to the [Advanced Usage](../examples/AdvancedUsage.js) example.
## API
### CacheMiddleware Class
#### Constructor
```javascript
const cache = new CacheMiddleware(maxSize, hybridOptions);
```- `maxSize`: Maximum size of the cache (default is `1000`).
- `hybridOptions`: Options for hybrid eviction policies (default is an empty object).#### Methods
- `set(key, value)`: Set a key-value pair in the cache.
- `get(key)`: Retrieve a value from the cache given its key.
- `invalidate(key)`: Mark a key as invalid.
- `remove(key)`: Remove a key from the cache and mark it as invalid.
- `clear()`: Clear the entire cache.
- `setCoherencyStrategy(strategy)`: Set the cache coherency strategy.### Eviction Policies
Cache-wizard supports the following eviction policies:
- FIFO (First-In, First-Out)
- LRU (Least Recently Used)
- LFU (Least Frequently Used)For detailed documentation and usage of eviction policies, please refer to the [Eviction Policies](./docs/EvictionPolicies.md) documentation.
## Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
## License
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
```Explanation:
- The README provides an overview of the Cache-wizard library, including installation instructions and basic usage examples.
- It also includes links to advanced usage examples and documentation for eviction policies.
- The API section outlines the methods and functionalities provided by the `CacheMiddleware` class.
- Information about contributing to the project and the license is also included.This README template provides users with essential information about the Cache-wizard package and guides them on how to use it effectively.