@isekaimaouyoki-sama/fastify-lrucache

1.0.3 • Public • Published

@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
})

Package Sidebar

Install

npm i @isekaimaouyoki-sama/fastify-lrucache

Weekly Downloads

1

Version

1.0.3

License

ISC

Unpacked Size

2.44 kB

Total Files

3

Last publish

Collaborators

  • isekaimaouyoki-sama