Skip to main content
Module

x/httpcache/redis_test.ts

HTTP Caching for Deno - in memory and redis storage support. Inspired by the Service Worker Cache API.
Latest
File
import { redisCache } from "./redis.ts";import { assert, assertEquals } from "./test_deps.ts";
Deno.test("[redis] cache, retrieve, delete", async () => { const cache = await redisCache("redis://127.0.0.1:6379", "cache-"); try { const originalResp = new Response("Hello World", { status: 200, headers: { "server": "deno", "cache-control": "public, max-age=604800, immutable", }, });
await cache.put("https://deno.land", originalResp);
const cachedResp = await cache.match("https://deno.land"); assert(cachedResp); assertEquals(originalResp.status, cachedResp.status); assertEquals( originalResp.headers.get("server"), cachedResp.headers.get("server"), ); assertEquals(await originalResp.text(), await cachedResp.text());
await cache.delete("https://deno.land");
const otherCachedResp = await cache.match("https://deno.land"); assert(otherCachedResp === undefined); } finally { cache.close(); }});