Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lucacasonato/deno_httpcache
HTTP Caching for Deno - in memory and redis storage support. Inspired by the Service Worker Cache API.
https://github.com/lucacasonato/deno_httpcache
cache deno redis serviceworker
Last synced: 26 days ago
JSON representation
HTTP Caching for Deno - in memory and redis storage support. Inspired by the Service Worker Cache API.
- Host: GitHub
- URL: https://github.com/lucacasonato/deno_httpcache
- Owner: lucacasonato
- License: mit
- Created: 2021-03-03T19:05:00.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-10-19T06:52:26.000Z (about 3 years ago)
- Last Synced: 2024-10-06T10:48:48.663Z (about 1 month ago)
- Topics: cache, deno, redis, serviceworker
- Language: TypeScript
- Homepage: https://deno.land/x/httpcache
- Size: 10.7 KB
- Stars: 25
- Watchers: 4
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# deno_httpcache
HTTP Caching for Deno - in memory and redis storage support. Inspired by the
Service Worker Cache API.## Usage
Setting, getting, and deleting items in the cache:
```ts
import { inMemoryCache } from "https://deno.land/x/[email protected]/in_memory.ts";const cache = inMemoryCache(5);
const req = new Request("https://deno.land/[email protected]/version.ts");
const resp = await fetch(req);await cache.set(req, resp);
const cachedResp = await cache.get(req); // or `cache.get(req.url)`
if (cachedResp === undefined) throw new Error("Response not found in cache");
console.log(cachedResp.status); // 200
console.log(cachedResp.headers.get("content-type")); // application/typescript; charset=utf-8await cache.remove(req); // or `cache.remove(req.url)`
console.log(await cache.get(req)); // undefined
```And with redis:
```ts
import { redisCache } from "https://deno.land/x/[email protected]/redis.ts";const cache = await redisCache("redis://127.0.0.1:6379");
// you can also optionally specify a prefix to use for the cache key:
const cache = await redisCache("redis://127.0.0.1:6379", "v1-");
```## Contributing
Before submitting a PR, please run these three steps and check that they pass.
1. `deno fmt`
2. `deno lint --unstable`
3. `deno test --allow-net` _this requires you to have a redis server running at
127.0.0.1:6379_