https://github.com/stellaraf/cacheutil
https://github.com/stellaraf/cacheutil
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/stellaraf/cacheutil
- Owner: stellaraf
- License: bsd-3-clause-clear
- Created: 2022-09-19T20:31:25.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-05-01T20:35:48.000Z (about 3 years ago)
- Last Synced: 2025-12-29T08:21:12.930Z (6 months ago)
- Language: TypeScript
- Size: 195 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
`@stellaraf/cacheutil` provides a consistent caching API with support for multiple backends in the event that a library requires a cache but could be used on multiple platforms with different caching systems available. For example, if one needed to use a library on both Cloudflare Workers and a standard NodeJS application.
# Supported Backends
## Cloudflare KV
```ts
import { createCache } from "@stellaraf/cacheutil-cache";
const cache = createCache(env.KV_BINDING);
await cache.set("key", "value");
const value = await cache.get("key");
console.log(value);
// value
```
## Redis
```ts
import { createCache } from "@stellaraf/cacheutil-cache";
const cache = createCache({ url: "redis://localhost:6379", database: 1 });
await cache.set("key", "value");
const value = await cache.get("key");
console.log(value);
// value
```