🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

@jpbberry/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

@jpbberry/cache

A caching structure with aquittable TTD

latest
Source
npmnpm
Version
1.0.4
Version published
Weekly downloads
3
50%
Maintainers
1
Weekly downloads
 
Created
Source

Cache

Installing

npm i @jpbberry/cache

Usage

Cache is an extension of Discord.JS's Collection, you can find docs here

Cache is essentially a temporary hold for data, that is cleared after inactivity.

You pass a time paramater to the constructor, which will wait that amount of time before clearing the data out of the cache. However everytime you do something with said data, like .get() it, said data's time til death with be reset, making it so you hold onto data until it is no longer actively being looked for.

Usage

const { Cache } = require('@jpbberry/cache')

const cache = new Cache(1000) // time in milliseconds

cache.set('a', 'b')

setTimeout(() => {
  console.log(cache.get('a')) // null
}, 1001)

But for example if you made the setTimeout 500, you would reset the time til death timer, so the cache would be available for another second.

I find this super easy in database caching implementation, where active searches are cached until they're no longer active.

Keywords

cache

FAQs

Package last updated on 18 Mar 2021

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