2.0.2 • Published 1 month ago

cachette v2.0.2

Weekly downloads
822
License
MIT
Repository
github
Last release
1 month ago

cachette

Resilient cache library supporting concurrent requests through local cache or Redis.

This repo is a work-in-progress and is not ready for general use.

Installation

npm install --save cachette

Basic usage

const { WriteThroughCache } = require('cachette');

// First, initialize the redis connection.
const cache = new WriteThroughCache(process.env.REDIS_URL);

async function fetchUrl(url) {
  console.log('fetching', url);
  const response = await fetch(url);
  console.log('fetched', url);
}

async function fetchUrlCached(url) {
  const fetchFunction = fetchUrl.bind(undefined, url);
  return cache.getOrFetchValue(url, 600, fetchFunction);
}

fetchUrlCached('https://unito.io').then(() => console.log('first call returned'));
// First call fetches the resource, the other calls use the cached value.
fetchUrlCached('https://unito.io').then(() => console.log('second call returned'));
fetchUrlCached('https://unito.io').then(() => console.log('third call returned'));

License

MIT

2.0.2

1 month ago

2.0.1

2 months ago

1.1.44

3 months ago

1.1.43

3 months ago

1.1.41

3 months ago

1.1.42

3 months ago

1.1.40

4 months ago

1.1.39

5 months ago

1.1.34

7 months ago

1.1.33

8 months ago

1.1.32

9 months ago

1.1.31

10 months ago

1.1.38

5 months ago

1.1.37

6 months ago

1.1.36

6 months ago

1.1.35

6 months ago

1.1.30

11 months ago

1.1.29

12 months ago

1.1.28

1 year ago

1.1.27

1 year ago

1.1.26

1 year ago

1.1.25

2 years ago

1.1.23

2 years ago

1.1.22

2 years ago

1.1.24

2 years ago

1.1.21

2 years ago

1.1.20

2 years ago

1.1.19

2 years ago

1.1.18

3 years ago

1.1.17

3 years ago

1.1.16

3 years ago

1.1.13

3 years ago

1.1.12

3 years ago

1.1.11

3 years ago

1.1.10

3 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.1

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago

1.0.0

7 years ago