1.1.3 • Published 3 years ago

cachelot v1.1.3

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

cachelot

A mutex based in-memory cache system JS

Installation

npm i cachelot --save

Usage

    const defaultExpiration: number = 5*60 * 1000; // 5 minutes
    const cleanupInterval: number = 1*60*1000 // 1minute
    const cache = cachelot.New(defaultExpiration, cleanupInterval)

    // with locking
    await cache.Set("key", "value", defaultExpiration + defaultExpiration)

    // without locking
    cache.set("key", "value", defaultExpiration + defaultExpiration)

     // with locking
    const [object, found] =  await cache.Get("key")
    const [object, expiration, found] =  await cache.GetWithExpiration("key")
    
    // without locking
     const [object, found] = cache.get("key")



    // on delete or every time janitor clean up the expired items this function would run
     cache.OnEvicted = (key, value) => {
         console.log(`Item expired & evicted => ${key} : ${value.toString()}`)
     }

Inspired from

go-cache

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.0.2

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago