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

pythagorean-cache

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pythagorean-cache

A cache that empties when full or at an interval

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

Pythagorean Cache

Build Status Coverage Status

🍷A cache that dumps when full or at an interval

cup

Example

import { PythagoreanCache } from 'pythagorean-cache';

// dump when size reaches 10
const cache = new PythagoreanCache<string>({ size: 10 });

cache.on('dump', () => {
  /* do something with 10 items */
});

for (let x = 0; x < 10; x++) {
  cache.push(`Hello ${x}`);
}

Options

  • size: The size of the cache. When the size is reached, a dump event is fired with all the items in the cache and then emptied
  • interval: The number of microseconds to wait before firing a dump event. This can be used to dump the cache at regular intervals.

These options can be combined, allowing you to create a cache that dumps at a certain size or at a certain interval.

Inspired Use Case

I was receiving a bursting stream of events I needed to add to a database. Instead of inserting each one as they come in, it was more efficient to do bulk inserts at intervals/sizes. This way that database was protected from burst events and I could expect the events to be inserted within a certain amount of time regardless.

Keywords

FAQs

Package last updated on 25 Apr 2019

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