An open API service indexing awesome lists of open source software.

https://github.com/0k/cache

Kids cache typescript implementation
https://github.com/0k/cache

Last synced: 10 months ago
JSON representation

Kids cache typescript implementation

Awesome Lists containing this project

README

          

# -*- ispell-local-dictionary: "english" -*-

#+TITLE: Typescript cache decorator

This packages holds a cache decorator implementation. It draws its
inspiration on [[https://pypi.python.org/pypi/kids.cache/][kids.cache]] a python simple yet powerful cache
decorator.

This implementation leverage decorator in typescript to reach same goals:

- no dependencies
- cache clearing support

Its still in infancy and lacks:

- support for normal function (only methods are cachable)
- cache stats
- 100% coverage
- doc

However, straying from [[https://pypi.python.org/pypi/kids.cache/][kids.cache]]:

- it leverages =Proxy= javascript niceties to provide a default
caching mechanism that records exactly what the function to be
cached used in the input arguments. This allows to have precise and
minimal footprints when looking for cache hits.

- as a consequence this part of the code is a little more ambitious
(bigger) than its counterpart.

* Adding =@0k/cache= to your project

From the root of your project:

#+begin_src sh
npm install --save @0k/cache
#+end_src

Or better, as =@0k/cache= is still in early release,

#+begin_src sh
npm install --save @0k/cache#master
#+end_src

To be sure to get the latest version, relaunch this last command
whenever you want to update.

* Contributing to =@0k/cache=

This package is using ~npm~ to track dependendies, so you can install them
with:

#+begin_src sh
npm install
#+end_src

As this package is written in =typescript=. You can transpile to
=javascript= and transpile on file change with:

#+begin_src sh
## Compile and watch
npx tspc -w
#+end_src

Tests are managed through =vitest=

#+begin_src sh
## Run test once
npm run test
#+end_src

Note that you can also use ~npx vitest~ command to launch tests in
watch mode.