Babel plugin for 'use cache' directive in Flight Framework
npm install @flightdev/babel-plugin-cachebash
pnpm add @flightdev/babel-plugin-cache
`
Usage
$3
`javascript
module.exports = {
plugins: [
['@flightdev/babel-plugin-cache', {
defaultTTL: 3600,
}],
],
};
`
$3
`typescript
async function getReviews(productId: string) {
"use cache";
return fetch(/api/reviews/${productId}).then(r => r.json());
}
`
$3
`typescript
import { cachedFn } from '@flightdev/cache-components';
const getReviews = cachedFn('getReviews', async (productId: string) => {
return fetch(/api/reviews/${productId}).then(r => r.json());
}, { ttl: 3600 });
`
Options
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| defaultTTL | number | 3600 | Default TTL in seconds |
| importSource | string | @flightdev/cache-components` | Import source |