Socket
Book a DemoInstallSign in
Socket

@commandkit/cache

Package Overview
Dependencies
Maintainers
2
Versions
238
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@commandkit/cache

CommandKit plugin that provides caching apis

0.0.0-dev.20250512141518
latest
Source
npmnpm
Version published
Weekly downloads
836
-41.25%
Maintainers
2
Weekly downloads
 
Created
Source

@commandkit/cache

CommandKit plugin for cache management.

Installation

npm install @commandkit/cache

Usage

To use the @commandkit/cache plugin, you need to add it to your CommandKit application. This can be done by importing the plugin and adding it to your configuration.

import { cache } from '@commandkit/cache';

export default defineConfig({
  plugins: [
    cache(),
  ],
})

Next, you can define advanced configurations for the plugin if needed. For example, you can set a custom cache provider:

import { setCacheProvider } from '@commandkit/cache';
import { RedisCache } from '@commandkit/redis';

setCacheProvider(new RedisCache({...}));

Then, you can add "use cache" directive to the function you want to cache. For example:

import { cacheTag, cacheLife } from '@commandkit/cache';

async function fetchDogs() {
  "use cache";

  cacheTag('dogs');
  cacheLife('1h');

  const dogs = await fetch('https://example.com/dogs');
  return dogs.json();
}

Now the fetchDogs function will be cached for 1 hour. You can perform on-demand cache invalidation or revalidation using the invalidate and revalidate methods:

import { invalidate, revalidate } from '@commandkit/cache';

async function refreshCache() {
  // invalidate the cache for the "dogs" tag. This will remove the cached data.
  // calling the function again will fetch fresh data.
  await invalidate('dogs');

  // revalidate the cache for the "dogs" tag. This will fetch fresh data and update the cache.
  await revalidate('dogs');
}

Keywords

commandkit

FAQs

Package last updated on 12 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.