GithubHelp home page GithubHelp logo

uzo-felix / cache-wizard Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 19 KB

๐Ÿšง Work in Progress ๐Ÿšง A middleware library for caching data with various eviction policies, cache invalidation, and cache coherency strategies.

License: MIT License

JavaScript 100.00%
cache-coherency cache-eviction-policy cache-invalidation cache-storage caching cache-middleware nodejs

cache-wizard's Introduction

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:

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

API

CacheMiddleware Class

Constructor

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

cache-wizard's People

Contributors

uzo-felix avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.