# ts-cache-service

> simple utility to cache API requests in different methods

Latest version **1.0.2** (published 2020-02-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install ts-cache-service
pnpm add ts-cache-service
yarn add ts-cache-service
bun add ts-cache-service
```

## 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.0.2 |
| Published | 2020-02-26 |
| First published | 2020-02-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Andrea Martini |
| Maintainers | capitanfindusfi |
| Keywords | typescript, cache, session-storage |

## Links

- npm: https://www.npmjs.com/package/ts-cache-service
- Repository: https://github.com/CapitanFindusFI/ts-cache-service
- Homepage: https://github.com/CapitanFindusFI/ts-cache-service#readme
- Issues: https://github.com/CapitanFindusFI/ts-cache-service/issues
- npm.io page: https://npm.io/package/ts-cache-service

## 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.0.2 (latest) — 2020-02-26
- 1.0.0 — 2020-02-24

## README

#TS Cache Service

This is a simple utilty lib which helps "caching" things based on a Map of key/value objects,
which can be stored in different ways.

It can be useful to store for example huge API responses, which are being almost never updated

### The Cache Service class

CacheService class, found in `src/index.ts` is a simple class with a `KeyGeneration` property (which is a function)
and a `cacheHandler` property, which is a `ICacheHandler` interface

Passing a `CacheType` to its constructor, will auto create a `cacheHandler` instance with a factory

Currently, there are 3 types of caching system:

#####`CacheType.MEMORY`

using `handlers/MemoryCacheHandler.ts` class, will store key/values in a simple object

##### `CacheType.SESSION`

using `handlers/SessionCacheHandler.ts` class, will store key/values inside `window.sessionStorage`

##### `CacheType.PERSISTENT`

using `handlers/PersistentCacheHandler.ts` class, will store key/values inside `window.localStorage`

It does automatically check if `window.sessionStorage` or `window.localStorage` are available,
and fallback to `CacheType.MEMORY` as default

inside `examples/axios` you can find an example using the Axios library with an adapter and a response interceptor to integrate with `CacheService`

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