isekaimaou1109 / fastify-lrucache

This package is a wrapper for lru-cache

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@isekaimaouyoki-sama/fastify-lrucache

This is a small wrapper around lru-cache.

Install

npm install --save @isekaimaouyoki-sama/fastify-lrucache

Usage

Easy to use require/import this plugin as below

const path = require('path')
const fastify = require('fastify')()

fastify.register(
  require('@isekaimaouyoki-sama/fastify-lrucache'),
  { 
    ttl: 1000 * 60 * 5, // 5 minutes
    allowStale: false,  // disable stale data
    ////////////////////// other options. You can see others in lru-cache options
  }
)

fastify.get("/", async function(request, reply) {
  fastify.cacher.set("a", 1)

  if (fastify.cacher.get('a') && +fastify.cacher.get('a') === 1) {
    reply.send("Valid data") 
  } else {
    reply.send("Invalid data") 
  } 
})

fastify.listen({ port: 3000 }, err => {
  if (err) throw err
})

About

This package is a wrapper for lru-cache


Languages

Language:JavaScript 100.0%