# tempting

> Save your temporary data in memory, databases (Redis, MySQL, etc.), and even files.

Latest version **0.0.3** (published 2022-10-05) · MIT license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2022-10-05 |
| First published | 2022-10-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 0 |
| Unpacked size | 86.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | kohai |
| Maintainers | gqxqd |
| Keywords | temp, cache |

## Links

- npm: https://www.npmjs.com/package/tempting
- Repository: https://github.com/kohaiy/tempting
- Issues: https://github.com/kohaiy/tempting/issues
- npm.io page: https://npm.io/package/tempting

## 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

- 0.0.3 (latest) — 2022-10-05
- 0.0.2 — 2022-10-01
- 0.0.1 — 2022-10-01
- 0.0.0 — 2022-10-01

## README

# Tempting

Save your temporary data in memory, databases (Redis, MySQL, etc.), and even files (under improvement).

## Install

```bash
npm install tempting
```

## API

```ts
export interface Adapter {
  set(key: string, value: string, expireIn?: number): Promise<boolean>;
  get(key: string): Promise<string | null>;
  del(key: string): Promise<boolean>;
}
export interface SyncAdapter {
  set(key: string, value: string, expireIn?: number): boolean;
  get(key: string): string | null;
  del(key: string): boolean;
}

export interface Tempting {
  set<T = string>(key: string, value: T, expireIn?: number): Promise<boolean>;
  get<T = string>(key: string): Promise<T | null>;
  del(key: string): Promise<boolean>;
}
export interface SyncTempting {
  set<T = string>(key: string, value: T, expireIn?: number): boolean;
  get<T = string>(key: string): T | null;
  del(key: string): boolean;
}
```

## Usage

```ts
import { createTempting, createFileAdapter } from 'tempting';

const temp = createTempting(createFileAdapter({ dirPath: './cache' }));

temp.set('name', 'value');
temp.get('name').then((value) => {
  console.log(value);
});

// set expire time
temp.set('token', 'value', 60);
temp.get('token').then((value) => {
  // will get null after 60s
  console.log(value);
});
```

The above is asynchronous storage, and the following is synchronous storage.

```ts
import { createSyncTempting, createMemoryAdapter } from 'tempting';

const temp = createSyncTempting(createMemoryAdapter());

temp.set('name', 'value');
console.log(temp.get('name'));

// set expire time
temp.set('token', 'value', 60);
// will get null after 60s
console.log(temp.get('token'));
```

## License

MIT

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