Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wilsonneto-dev/small-cache
:wrench: Small Cache - JS/TS Library - The simplest, easiest, and most minimalist way to cache your requests on your frontend (JS/TS)
https://github.com/wilsonneto-dev/small-cache
cache frontend javascript package typescript
Last synced: 3 days ago
JSON representation
:wrench: Small Cache - JS/TS Library - The simplest, easiest, and most minimalist way to cache your requests on your frontend (JS/TS)
- Host: GitHub
- URL: https://github.com/wilsonneto-dev/small-cache
- Owner: wilsonneto-dev
- Created: 2021-09-10T03:35:35.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-09-13T00:34:53.000Z (about 1 year ago)
- Last Synced: 2024-10-28T13:58:48.833Z (19 days ago)
- Topics: cache, frontend, javascript, package, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/small-cache
- Size: 21.5 KB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Small Cache
🎈 The simplest, easiest, and most minimalist way 😃 to cache your requests on your frontend (JS/TS, with React.js, Next.js, Vue.js, Angular, and all others)
Install it in your project:
```console
npm i small-cache
# or
yarn add small-cache
```Import in your project:
```js
import { getFromCache } from 'small-cache'
```Then use it as easy as this:
```ts
const creatorsListData = await getFromCache(
'creators', // cache key
async () => await creatorsService.get() // the fetch data function
)
```Or as simple as:
```ts
const product = await getFromCache(
'product-123', // cache key
async () => { // the fetch data function
const { data } = await axios.get('https://example.com/products/123')
return data;
}
)
```You can also control the cache TTL (Time to Live) or disable caching using a third parameter, the options:
```ts
const creatorsListData = await getFromCache(
'creators', // cache key
async () => await creatorsService.get(), // the fetch data function,
{ // options parameter
TTL_InSeconds: 60, // cache TTL (time to expire in seconds)
enabled: true // enable or disable the caching
}
)
```---
And yes, that's all!
Life can be simple sometimes ✨