New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

yaloc

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

yaloc

A loading cache data structure for web and node.

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

Yet Another LOading Cache (yaloc)

A loading cache data structure for web and node, written in TS.

Inspired by guava's LoadingCache.

Installation

yarn add yaloc

npm install --save yaloc

Usage

(Please see tests for the most up to date, guaranteed behaviour.)

basic

import { LoadingCache } from 'yaloc';

const cache = new LoadingCache((key: WhateverType) => getValueFromRemoteSource(key));

await cache.get("foo");
await cache.get("foo"); // doesn't call `getValueFromRemoteSource` for `"foo"`

full example

import { LoadingCache } from 'yaloc';

const cache = new LoadingCache<string, string>({
  loader: (key) => getValueFromRemoteSource(key),
  expireAfterAccess: 60 * 1000 // removes an entry, if it hasn't been accessed for a minute
  expireAfterWrite: 5 * 60 * 1000 // removes an entry, 5 minutes after it has been loaded
  refreshAfterWrite: 15 * 1000 // reloads an entry every 15 seconds
  onRemove: ([key, value], removalCause) => { // called whenever an entry is removed from the cache
    console.log(`value for ${key} is removed because ${removalCause}`);
  }
})

Roadmap

  • [] more test coverage
  • [] more examples
  • [] timeUnit support for expire and refresh options
  • [] maximumSize support
  • [] LoadingCacheBuilder that is an alternative to passing all options new LoadingCache({ ... })
  • [] ?? WeakLoadingCache that is backed by WeakMap, probably without expiration features.

Keywords

loading cache

FAQs

Package last updated on 21 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