An open API service indexing awesome lists of open source software.

https://github.com/stellaraf/cacheutil


https://github.com/stellaraf/cacheutil

Last synced: 2 months ago
JSON representation

Awesome Lists containing this project

README

          







Stellar JS Cache Utilities











`@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
```