https://github.com/matschik/micache
Simple cache & fetching data cache strategy ⚡
https://github.com/matschik/micache
Last synced: 2 months ago
JSON representation
Simple cache & fetching data cache strategy ⚡
- Host: GitHub
- URL: https://github.com/matschik/micache
- Owner: matschik
- Created: 2021-07-17T03:04:38.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-04-18T19:58:02.000Z (over 3 years ago)
- Last Synced: 2025-07-02T12:06:09.759Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 26.4 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Micache ⚡
> Simple cache & caching fetched data strategy
[](https://badge.fury.io/js/micache)
🪶 Just lightweight
## `createCache`
### Simple cache
```js
import { createCache } from "micache";const myCache = createCache();
myCache.set("123", { name: "Denji" });
myCache.get("123"); // { name: "Denji" }
```### Cache with expiring keys
```js
import { createCache } from "micache";const myTemporaryCache = createCache({ expireSec: 30 });
myTemporaryCache.set("567", { name: "Power" });
myTemporaryCache.get("567"); // { name: "Power" }
// 30 seconds later ...
myTemporaryCache.get("567"); // undefined
```## `createAsyncCache`
```js
import { createAsyncCache } from "micache";
import redaxios from "redaxios";async function fetchPrice(fromCoinId, toCoinId){
const response = await redaxios.get(
"https://min-api.cryptocompare.com/data/pricemultifull",
{
params: {
fsyms: fromCoinId,
tsyms: toCoinId,
},
}
);return response.data.RAW[fromCoinId][toCoinId].PRICE;
}const getPrice = createAsyncCache(fetchPrice, { expireSec: 30 });
let price = await getPrice("BTC", "USD"); // 46201,98
price = await getPrice("BTC", "USD"); // very fast with cache => 46201,98
// 30 seconds later ...
price = await getPrice("BTC", "USD"); // 46337,73
```## `createFsCache`
Create cache using filesystem.
Cache is stored in `node_modules/.micache-fs` folder.## `createFileMapCache`
Create a mapping between file content and data related to this content.
This method is using `createFsCache` to store cache.