import { Zoic } from "https://deno.land/x/zoic@v1.0.5/zoic.ts";
Class to initalize new instance of cache. Takes options to define if cache eviction policy, expiration time for cache itmes, and if response should be returned on cache hit.
Example
import { Zoic } from "https://deno.land/x/zoic/zoic.ts"
const cache = new Zoic({
cache: 'LRU',
expire: '2h, 5m, 3s',
capacity: 200
});
router.get('/dbRead', cache.use, controller.dbRead, ctx => {
ctx.response.body = ctx.state.somethingFromDb;});
Wtih Redis
Note: with Reids options "expire" and "capacity" do not apply.
const cache = new Zoic({
cache:'Redis',
port: 6379
})
Properties
metrics: PerfMetrics
Methods
endPerformanceMark(queryRes: "hit" | "miss")
Marks end of latency test for cache hit or miss, and updates read or write processed
getMetrics(ctx: Context)
Retrives cache metrics. Designed for use with Chrome extension.
redisTypeCheck(cache: LRU | LFU | Redis): cache is Redis
typecheck for Redis cache