Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@ import { Cacheable, MemoryBucket } from 'cacheables'

const cache = new Cacheable('app', { buckets: [new MemoryBucket()] })

// Cache the parsed JSON, not the Response — a Response body can be
// consumed exactly once, so caching the Response itself would break
// every call after the first .json().
const data = await cache.remember(
() => fetch('https://some-url.com/api').then((r) => r.json()),
'key',
)
const data = await cache.remember(() => fetchData(), 'key')
```

- [Installation](#installation)
Expand Down Expand Up @@ -71,8 +65,6 @@ const cache = new Cacheable('weather-data', {

// `remember` is both getter and setter: on a miss it calls the resource
// and writes to every bucket; on a hit it returns the cached value.
// Cache the parsed JSON rather than the Response object — the Response
// body can only be read once.
const getWeather = () =>
cache.remember(() => fetch(apiUrl).then((r) => r.json()), 'karlsruhe')

Expand Down
Loading