📅 You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP
Socket
Sign inDemoInstall
Socket

fast-node-cache

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-node-cache

A simple and powerful cache.

1.2.1
latest
Source
npm
Version published
Maintainers
1
Created
Source

Fast Node Cache

Simple yet powerful cache used by PreMiD.

Why?

Caching is one of the most important things to do in production; futhermore, preventing your databases from getting bombarded with requests or to cache results from an API which only allows a certain amount of requests.

TODO

  • Sync between workers (Sync ID's to have multiple managers)
  • LRU caching strategy

Installation

# npm
$ npm i fast-node-cache

# yarn
$ yarn add fast-node-cache

Usage

Creating a "CacheManager"

A CacheManager is the main entry to access, set and listen to events from the cache.

  cacheManager = new CacheManager(options?);

The CacheManager has a set of options that can be changed:

OptionTypeDefault ValueDescription
memoryOnly?booleantrueWether or not the cache is stored in memory (RAM) only or should be saved to a file as well as an redundancy measure.
cacheDirectory?string__dirname + .cacheAllows to change the default cache folder that's used to load and save the cache.
defaultExpire?number300000 (5 minutes)Changes the default time in miliseconds when cache is considered outdated.
checkInterval?number250 (4 times a second)Changes the default checkInterval to check for outdated caches.
discardTamperedCachebooleanfalseWether or not to delete corrupted cache on startup

Listening to events

  //* Emitted when the cache is updated
  cacheManager.on(event: "update", listener: Function<name:string, data:any>, options?: {only?:string[] | string})

  //* Emitted when the cache is outdated
  cacheManager.on(event: "outdated", listener: Function<name:string, data:any>, options?: {only?:string[] | string})

Setting a cached object

cacheManager.set(name: string, data: any, expires?: number)

Getting a cached object

cacheManager.get(name: string)

Checking if a cached object has expired

cacheManager.isExpired(name: string)

Returns all keys in the cache

cacheManager.keys()

Returns all values in the cache

cacheManager.values()

Returns all entries in the cache

cacheManager.entries()

Keywords

fast

FAQs

Package last updated on 17 Aug 2020

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