0.3.2 • Published 3 years ago

typecache v0.3.2

Weekly downloads
1
License
MIT
Repository
github
Last release
3 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

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago