# @tadashi/find-in-cache

> Find data in cache

Latest version **3.0.0** (published 2024-09-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @tadashi/find-in-cache
pnpm add @tadashi/find-in-cache
yarn add @tadashi/find-in-cache
bun add @tadashi/find-in-cache
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2024-09-08 |
| First published | 2021-02-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=20 |
| Dependencies | 3 |
| Unpacked size | 9.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Thiago Lagden |
| Maintainers | lagden |
| Keywords | cache, redis, lib, find |

## Links

- npm: https://www.npmjs.com/package/@tadashi/find-in-cache
- Repository: https://github.com/lagden/find-in-cache
- Homepage: https://github.com/lagden/find-in-cache#readme
- Issues: https://github.com/lagden/find-in-cache/issues
- npm.io page: https://npm.io/package/@tadashi/find-in-cache

## Dependencies (3)

- [@tadashi/hash](https://npm.io/package/@tadashi/hash.md) 3.0.1
- [@tadashi/common](https://npm.io/package/@tadashi/common.md) 4.6.0
- [@tadashi/cache-redis](https://npm.io/package/@tadashi/cache-redis.md) 7.0.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

- 3.0.0 (latest) — 2024-09-08
- 2.4.1 — 2023-12-14
- 2.4.0 — 2023-12-05
- 2.3.0 — 2023-06-12
- 2.2.2 — 2022-11-29
- 2.2.1 — 2022-04-02
- 2.2.0 — 2021-08-24
- 2.1.0 — 2021-06-24
- 2.0.0 — 2021-06-24
- 1.1.0 — 2021-04-27
- 1.0.0 — 2021-02-25

## README

# find-in-cache

[![NPM version][npm-img]][npm]
[![Node.js CI][ci-img]][ci]
[![Coverage Status][coveralls-img]][coveralls]

[npm-img]:         https://img.shields.io/npm/v/@tadashi/find-in-cache.svg
[npm]:             https://www.npmjs.com/package/@tadashi/find-in-cache
[ci-img]:          https://github.com/lagden/find-in-cache/actions/workflows/nodejs.yml/badge.svg
[ci]:              https://github.com/lagden/find-in-cache/actions/workflows/nodejs.yml
[coveralls-img]:   https://coveralls.io/repos/github/lagden/find-in-cache/badge.svg?branch=main
[coveralls]:       https://coveralls.io/github/lagden/find-in-cache?branch=main


Find in cache


## Install

```
$ npm i @tadashi/find-in-cache
```

## Environment variable

| variable              | type       | required    | default            | description  |
| --------              | ---------- | ----------- | --------------     | ------------ |
| REDIS                 | string     | no          | 127.0.0.1:6379     | The address or addresses of the Redis server(s) |
| REDIS_PWD             | string     | no          | -                  | The password for authenticating with the Redis server, if required |
| CACHE_REDIS_PREFIX    | string     | no          | lib                | Key prefix |
| CACHE_REDIS_NAMESPACE | string     | no          | find-in-cache      | Avoid conflicts between caches |
| CACHE_REDIS_DB        | number     | no          | 0                  | Number of database |
| CACHE_REDIS_OPTIONS   | JSONString | no          | {}                 | [See configuration options](https://redis.github.io/ioredis/interfaces/CommonRedisOptions.html) |
| CLEAR_CACHE_FIRST_RUN | boolean    | no          | true               | Clear cache when app is started |


## API

### find(key): Promise<*>

| parameter   | type     | required    | default     | description |
| --------    | -------- | ----------- | ----------- | ------------ |
| key         | string   | yes         | -           | The key for which to find the cached value |


### caching(key, value, ttl): Promise\<Object\>

| parameter   | type           | required    | default     | description |
| --------    | -------------- | ----------- | ----------- | ------------ |
| key         | string         | yes         | -           | The key under which the value will be stored |
| value       | any            | yes         | -           | The value to be cached |
| ttl         | string\|number | no          | -           | The time-to-live for the cache entry, in seconds |


> [!IMPORTANT]  
> If the `ttl` is not set, the cache will last forever


## Usage

```js
import {find, caching, cache} from '@tadashi/find-in-cache'

await find('foo')
// => undefined

await caching('foo', 'bar', 30)
// => {'OK', 1}

await find('foo')
// => bar

await cache.clear()
// => cache was cleared
```

---

> [!IMPORTANT]  
> Buy me a coffee!  
> BTC: `bc1q7famhuj5f25n6qvlm3sssnymk2qpxrfwpyq7g4`


## License

MIT © [Thiago Lagden](https://github.com/lagden)

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