Cache Plugin
The cache plugin for CommandKit enables caching APIs in your project. It provides a simple and efficient way to cache data, reducing the need for repeated database queries or API calls.
Installation
- npm
- yarn
- pnpm
npm install @commandkit/cache
yarn add @commandkit/cache
pnpm add @commandkit/cache
Usage
This plugin automatically registers the in-memory cache provider with your CommandKit instance.
import { defineConfig } from 'commandkit';
import { cache } from '@commandkit/cache';
export default defineConfig({
plugins: [cache()],
});
Then, you can add the "use cache"
directive to the function you want to cache. For example:
async function getCachedData() {
'use cache'; // This directive enables caching for the function
// Your data retrieval logic
const data = await getFromDatabase('something');
return data;
}
To understand more about the caching system, check out the Caching in CommandKit guide.