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

cache-mapset

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cache-mapset

Maps and Sets with cache replacement policies, TC39 proposal-policy-map-set implementation

  • 1.0.0-beta.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
Maintainers
1
Weekly downloads
 
Created
Source

cache-mapset

deno land deno doc GitHub release (latest by date) codecov License

test NPM standard-readme compliant semantic-release: angular

Maps and Sets with cache replacement policies, TC39 proposal-policy-map-set implementation. This can be used as a cache for TC39 proposal-function-memo and its implementation.

Usage

FIFO

FIFO(First In, First Out) implementations.

FIFOMap

When the upper limit is reached, replaces the entry with FIFO algorithm.

import { FIFOMap } from "https://deno.land/x/cache_mapset@$VERSION/mod.ts";

declare const maxNumOfEntries: number;
const map = new FIFOMap(maxNumOfEntries);
FIFOSet

When the upper limit is reached, replaces the value with FIFO algorithm.

import { FIFOSet } from "https://deno.land/x/cache_mapset@$VERSION/mod.ts";

declare const maxNumOfValues: number;
const set = new FIFOSet(maxNumOfValues);

LIFO

LIFO(Last In, First Out) implementations.

LIFOMap

When the upper limit is reached, replaces the entry with LIFO algorithm.

import { LIFOMap } from "https://deno.land/x/cache_mapset@$VERSION/mod.ts";

declare const maxNumOfEntries: number;
const map = new LIFOMap(maxNumOfEntries);
LIFOSet

When the upper limit is reached, replaces the value with LIFO algorithm.

import { LIFOSet } from "https://deno.land/x/cache_mapset@$VERSION/mod.ts";

declare const maxNumOfValues: number;
const set = new LIFOSet(maxNumOfValues);

LRU

LRU(Least Recently Used) implementations.

LRUMap

When the upper limit is reached, replaces the entry with LRU algorithm.

import { LRUMap } from "https://deno.land/x/cache_mapset@$VERSION/mod.ts";

declare const maxNumOfEntries: number;
const map = new LRUMap(maxNumOfEntries);
LRUSet

When the upper limit is reached, replaces the value with LRU algorithm.

import { LRUSet } from "https://deno.land/x/cache_mapset@$VERSION/mod.ts";

declare const maxNumOfValues: number;
const set = new LRUSet(maxNumOfValues);

LFU

LFU(Least Frequently Used) implementations.

LFUMap

When the upper limit is reached, replaces the entry with LFU algorithm.

import { LFUMap } from "https://deno.land/x/cache_mapset@$VERSION/mod.ts";

declare const maxNumOfEntries: number;
const map = new LFUMap(maxNumOfEntries);
LFUSet

When the upper limit is reached, replaces the value with LFU algorithm.

import { LFUSet } from "https://deno.land/x/cache_mapset@$VERSION/mod.ts";

declare const maxNumOfValues: number;
const set = new LFUSet(maxNumOfValues);

Common

List items common to all implementations.

Interface

All instance have following members.

MapLike:

interface MapLike<K, V> {
  /** The number of entries. */
  size: number;

  /** Whether has an entry with the given {@link key}. */
  has: (key: K) => boolean;

  /** Returns the value of the entry with the given {@link key}, if any such entry exists; otherwise returns `undefined`. */
  get: (key: K) => V | undefined;

  /** Adds an entry with the given {@link key} mapped to the given {@link value}. */
  set: (key: K, value: V) => this;

  /** Deletes the entry with the given {@link key}. */
  delete: (key: K) => boolean;

  /** Removes all entries. */
  clear: () => void;
}

SetLike:

interface SetLike<T> {
  /** The number of values. */
  size: number;

  /** Whether has the given {@link value}. */
  has: (value: T) => boolean;

  /** Adds the given {@link value}. */
  add: (value: T) => this;

  /** Deletes the given {@link value}. */
  delete: (value: T) => boolean;

  /** Removes all values. */
  clear: () => void;
}

Throwing error

All constructors specify a capacity as their first argument.

If it is a negative number, an error is thrown.

import { FIFOMap } from "https://deno.land/x/cache_mapset@$VERSION/mod.ts";
import { assertThrows } from "https://deno.land/std/testing/asserts.ts";

assertThrows(() => new FIFOMap(-1));

API

See deno doc for all APIs.

Contributing

See CONTRIBUTING.md

License

MIT © 2023 Tomoki Miyauchi

Keywords

FAQs

Package last updated on 18 Jun 2023

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