# cachelot

> locking based inMemory cache

Latest version **1.1.3** (published 2021-05-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install cachelot
pnpm add cachelot
yarn add cachelot
bun add cachelot
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.3 |
| Published | 2021-05-23 |
| First published | 2021-05-17 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 33.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | praveenkumarkajla |
| Maintainers | kajlapk |
| Keywords | mutex, lock, in-memory cache, redis, lock |

## Links

- npm: https://www.npmjs.com/package/cachelot
- Repository: https://github.com/praveenkumarKajla/cachelot
- Homepage: https://github.com/praveenkumarKajla/cachelot#readme
- Issues: https://github.com/praveenkumarKajla/cachelot/issues
- npm.io page: https://npm.io/package/cachelot

## Dependencies (1)

- [async-mutex](https://npm.io/package/async-mutex.md) ^0.3.1

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 1.1.3 (latest) — 2021-05-23
- 1.1.2 — 2021-05-21
- 1.1.1 — 2021-05-21
- 1.1.0 — 2021-05-21
- 1.0.2 — 2021-05-21
- 1.0.1 — 2021-05-17
- 1.0.0 — 2021-05-17

## README

# cachelot
A mutex based in-memory cache system JS

Installation

`npm i cachelot --save`

Usage

```typescript

    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](https://github.com/patrickmn/go-cache)

---
_Source: https://npm.io/package/cachelot · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
