Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/zoic/zoic.ts>default

A caching middeware library for Deno HTTP framework, Oak.
Go to Latest
class default
import { default } from "https://deno.land/x/zoic@v1.0.2/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
 })

Constructors

new
default(options?: options)

Properties

cache: Promise<LRU | Redis>
capacity: number
expire: number
metrics: InstanceType<PerfMetrics>
respondOnHit: boolean

Methods

clear(ctx: Context, next: () => Promise<unknown>)

Manually clears all current cache entries.

endPerformanceMark(queryRes: "hit" | "miss")

Marks end of latency test for cache hit or miss, and updates read or write processed

Retrives cache metrics. Designed for use with Chrome extension.

put(ctx: Context, next: () => Promise<unknown>)

Manually sets response to cache.

redisTypeCheck(cache: LRU | Redis): cache is Redis

typecheck for Redis cache

use(ctx: Context, next: () => Promise<unknown>)

Primary caching middleware method on user end. Resposible for querying cache and either returning results to client/attaching results to ctx.state.zoic (depending on user options) or, in the case of a miss, signalling to make response cachable.