@flightdev/babel-plugin-cache
v0.0.3
Published
Babel plugin for 'use cache' directive in Flight Framework
Maintainers
Readme
@flightdev/babel-plugin-cache
Babel plugin for "use cache" directive in Flight Framework.
Installation
pnpm add @flightdev/babel-plugin-cacheUsage
babel.config.js
module.exports = {
plugins: [
['@flightdev/babel-plugin-cache', {
defaultTTL: 3600,
}],
],
};In Code
async function getReviews(productId: string) {
"use cache";
return fetch(`/api/reviews/${productId}`).then(r => r.json());
}Output
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 |
