Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arugaz/elysia-cache
Plugin for Elysia that for LRU Caching
https://github.com/arugaz/elysia-cache
bun cache elysia lru
Last synced: 3 months ago
JSON representation
Plugin for Elysia that for LRU Caching
- Host: GitHub
- URL: https://github.com/arugaz/elysia-cache
- Owner: arugaz
- License: mit
- Created: 2023-09-13T13:42:15.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-09-13T17:11:15.000Z (over 1 year ago)
- Last Synced: 2024-05-21T08:50:31.476Z (7 months ago)
- Topics: bun, cache, elysia, lru
- Language: TypeScript
- Homepage:
- Size: 17.6 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# elysia-cache
Plugin for [elysia](https://github.com/elysiajs/elysia) that add support for lru cache.## Installation
```bash
bun add elysia-cache
```## Example
```typescript
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.valuecache.set(key, value)
return new Response('done')
})
.get('/get', ({ query, cache }) => {
const key = query.keyconst 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 cacheType:
```typescript
has(key: string) => boolean
```### remove
A function to delete cache from given keyType:
```typescript
remove(key: string) => void
```### get
A function to retrieve value in the cache, return null if the value is not in the cache.Type:
```typescript
get(key: string | number) => any
```### set
A function to update cache value from given keyType:
```typescript
set(key: string | number, value: any) => void
```### clear
A function to flush all cacheType:
```typescript
clear() => void
```