0.3.2 • Published 2 years ago

typecache v0.3.2

Weekly downloads
1
License
MIT
Repository
github
Last release
2 years ago

typecache

Customizable caching library for TypeScript

Install

npm i typecache

Usage

import LRU from 'lru-cache'
import { cache, LRUStore } from 'typecache'

const store = new LRUStore(new LRU<string, any>({ max: 10 }))
const { Store, Update, Remove } = cache(store)

class Service {

  // Store the result in the cache and return that if it's called again
  @Store((id: string) => `user-${id}`)
  async getUser (id: string) {
    const res = await fetch(`/user/${id}`)
    return res.json()
  }

  // Replace the existing value in the cache
  @Update((id: string) => `user-${id}`)
  async updateUser (id: string) {
    const res = await fetch(`/user/${id}/update`)
    return res.json()
  }

  // Remove the keys from the cache
  @Remove((id: string) => [`user-${id}`])
  async deleteUser(id: string) {
    const res = await fetch(`/user/${id}/delete`)
    return res.json()
  }

}
0.3.0

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago