Giter Site home page Giter Site logo

benhurdavies / node-cache-engine Goto Github PK

View Code? Open in Web Editor NEW
12.0 7.0 1.0 783 KB

High performing caching package for node/javascript

Home Page: https://www.npmjs.com/package/node-cache-engine

License: MIT License

Shell 0.75% TypeScript 99.25%
cache-engine custom-hashtable lru cache-replacement least-frequently-used javascript node-cache least-recently-used lfu lfu-cache

node-cache-engine's Introduction

node-cache-engine (supports browser and node)

Simple and High performing cache engine package for node/javascript. It using default cache replacement is LRU (Least Recently Used) cache engine and hash table as javascript Map Object.

Installation

npm install --save node-cache-engine
import { createCache } from 'node-cache-engine';

const cache = createCache(); // creating instance of cache with default configuration

cache.add('key', 'value'); // add into cache
cache.get('key'); // get from cache
cache.has('key'); // checking from key is existing in cache
cache.remove('key'); // removing from cache
cache.size(); // get the size of cache

Option for creating cache instance

import { createCache } from 'node-cache-engine';

const cache = createCache({
  size: 100, // Maximum size for the cache. default value is Number.MAX_SAFE_INTEGER
  engine: 'LRU', // cache replacement engine default is LRU (Least Recently Used)
  HashTable: YourCustomHashTable, // for custom hash Table. default hashTable is 'src/dataStructure/HashTable.js'
});

Supported cache replacement engines and options

Engines Name key supported options
Least Recently Used LRU HashTable, size
Least Frequently Used LFU HashTable, size

Time complexity of engine methods

Engine Method Time complexity
LRU/LFU add O(1)
get O(1)
has O(1)
remove O(1)
size O(1)

Methods available on cache engines

Methods LRU LFU
add
get
has
remove
size
clearAll
toArray

Creating Custom HashTable

When and Why you should create custom hash table?
The default hash table implemented with Map. If you want much more performance than default you can implement your own (like node wrapped c++ hash table). I think 1 to 5 million cache entry default hash table is fine if your use case is more than this go for custom hash table.

To implement custom hashTable you have to use methods with symbols name provided from the package. example

Next?

  • TTL engine
  • TTL combining with LRU engine

Contribute

Contributions to this project are always welcome.
Please read CONTRIBUTING.md for a How-to.

node-cache-engine's People

Contributors

benhurdavies avatar benhurdavies-a avatar tarszator avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

anuvargheseben

node-cache-engine's Issues

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.