You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{request}from"keq";import{cache,MemoryStorage}from"keq-cache";request.use(cache({storage: newMemoryStorage(),rules: [{pattern: (ctx)=>ctx.request.method==="get"&&ctx.request.url.pathname==="/example",strategy: Strategy.STALE_WHILE_REVALIDATE,ttl: 5*60,key: (ctx)=>ctx.request.__url__.href,exclude: async(response)=>response.status!==200,},],}));/// This request will be cacherequest.get("/example");/// This won't be cacherequest.post("/cat");
Global Middleware and Enable on demand
import{request}from"keq";import{cache,MemoryStorage}from"keq-cache";request.use(cache({storage: newMemoryStorage()}));/// This request will be cacherequest.get("/example").options({cache: {strategy: Strategy.STALE_WHILE_REVALIDATE,key: "custom-cache-key",exclude: async(response)=>response.status!==200,ttl: 1,},});/// This won't be cacherequest.get("/example");
OneTime Middleware
import{request,KeqMiddleware}from"keq";import{cache,MemoryStorage}from"keq-cache";conststorage=newMemoryStorage();functionswr(): KeqMiddleware{returncache({
storage,rules: [{strategy: Strategy.STALE_WHILE_REVALIDATE,ttl: 5*60,key: (ctx)=>ctx.request.__url__.href,exclude: async(response)=>response.status!==200,},],});}/// This request will be cacherequest.get("/example").use(swr());/// This won't be cacherequest.get("/example");