Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/susisu/catcher

fetcher with cache
https://github.com/susisu/catcher

Last synced: 2 days ago
JSON representation

fetcher with cache

Awesome Lists containing this project

README

        

# @susisu/catcher

[![CI](https://github.com/susisu/catcher/workflows/CI/badge.svg)](https://github.com/susisu/catcher/actions?query=workflow%3ACI)

``` shell
# npm
npm i @susisu/catcher
# yarn
yarn add @susisu/catcher
# pnpm
pnpm add @susisu/catcher
```

## Usage

``` typescript
import { Catcher } from "@susisu/catcher";

const catcher = new Catcher({
fetcher: () => fetchFromSource(params),
});

// data1 = data fetched from the source
const data1 = await catcher.fetch();

// data2 = cached data equal to data1
const data2 = await catcher.fetch();

// expire the cache
catcher.expire();

// data3 = refetched data from the source
const data3 = await catcher.fetch();
```

## License

[MIT License](http://opensource.org/licenses/mit-license.php)

## Author

Susisu ([GitHub](https://github.com/susisu), [Twitter](https://twitter.com/susisu2413))