Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-cache-engine

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-cache-engine

High performing cache library (with cache replacement) for browser and node

  • 2.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
184
increased by411.11%
Maintainers
2
Weekly downloads
 
Created
Source

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 Namekeysupported options
Least Recently UsedLRUHashTable, size
Least Frequently UsedLFUHashTable, size
Time complexity of engine methods
EngineMethodTime complexity
LRU/LFUaddO(1)
getO(1)
hasO(1)
removeO(1)
sizeO(1)

Methods available on cache engines

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

Keywords

FAQs

Package last updated on 13 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc