2.0.0 • Published 4 months ago

nwaycache v2.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

Azupay Cache

Implementation of in-memory n-way set associative cache base on arrays. This cache supports eviction strategies. Implementation of LRU eviction strategy is provided by this library.

Installation

  npm install nwaycache

Usage

import {AzupayCache, LRUEvictionPolicy} from "nwaycache";

let lruEvictionPolicy = new LRUEvictionPolicy<string>(10);
let azupayCache = new AzupayCache<string, string>(10, lruEvictionPolicy);
azupayCache.put("1234","aaaa");
azupayCache.put("1235","aaaab");

console.log(azupayCache.get("1234"));
console.log(azupayCache.get("1235"));

API Documentation

Simple in-memory implementation of fixed size N-way associative cache.

LRUEvictionPolicy

Implementation of LRU eviction policy.

constructor(size: number)

size - limit number of associations

AzupayCache

Implementation of memory cache

constructor(size: number, evictionPolicy: ICacheEvictionPolicy)

size - size of cache, number of buckets.

evictionPolicy - object implementing eviction policy for cache.

put(key: K, value: V): void

Inserts new association value into a cache for key key. If another value already stored in cache for this key, then it will be replaced.

get(key: K): V | undefined

Fetched value associated with key and updates its usage. Returns undefined if no value is stored.

delete(key: K): void

Removes association for key from cache.

listAll(key: K): V[] | undefined

Fetches all associations for key. Returns undefined if there is nothing for specified key.

Contribution

  • Download the project.
  • Make your change or bug fix.
  • Create git patch.
  • Send me the patch.

Changelog

v2.0.0 - change cache implementation from Map to Arrays. Updated ICacheEvictionPolicy API v1.0.2 - export ICacheEvictionPolicy v1.0.0 - Initial implementation of in-memory cache and LRU eviction policy

2.0.0

4 months ago

1.0.2

4 months ago

1.0.1-latest

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago