🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

elysia-cache

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elysia-cache

Plugin for Elysia that for LRU Caching

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

elysia-cache

Plugin for elysia that add support for lru cache.

Installation

bun add elysia-cache

Example

import { Elysia } from 'elysia'
import { cache } from 'elysia-cache'

const app = new Elysia()
    .use(cache())
    .get('/set', ({ query, cache }) => {
      const key = query.key
      const value = query.value

      cache.set(key, value)

      return new Response('done')
    })
    .get('/get', ({ query, cache }) => {
      const key = query.key

      const value = cache.get(key)

      return {
        value: value
      }
    })
    .get('/flush', ({ cache }) => cache.clear())
    .listen(8080)

Config

Below are configurable properties for using LRU cache plugin.

max

The maximum object that can be stored.

Handler

Below are the value added to the handler.

has

A function to check cache

Type:

has(key: string) => boolean

remove

A function to delete cache from given key

Type:

remove(key: string) => void

get

A function to retrieve value in the cache, return null if the value is not in the cache.

Type:

get(key: string | number) => any

set

A function to update cache value from given key

Type:

set(key: string | number, value: any) => void

clear

A function to flush all cache

Type:

clear() => void

Keywords

elysia

FAQs

Package last updated on 13 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts