@@ -44,10 +44,10 @@ Let's build a simple XP system using CommandKit's caching feature. We'll create:
4444### XP Command
4545
4646``` js
47- import { SlashCommandProps , CommandData , cacheTag } from ' commandkit' ;
47+ import { SlashCommand , CommandData , cacheTag } from ' commandkit' ;
4848import { database } from ' ../database' ;
4949
50- export const data = {
50+ export const command : CommandData = {
5151 name: ' xp' ,
5252 description: ' Check your XP' ,
5353};
@@ -63,7 +63,7 @@ async function getUserXP(guildId, userId) {
6363 return xp;
6464}
6565
66- export async function run ({ interaction }) {
66+ export const chatInput : SlashCommand = async ({ interaction }) => {
6767 await interaction .deferReply ();
6868
6969 const xp = await getUserXP (interaction .guildId , interaction .user .id );
@@ -124,10 +124,8 @@ const fetchPokemon = cache(
124124async function fetchUserProfile (userId ) {
125125 ' use cache' ;
126126
127- cacheTag ({
128- tag: ` user-${ userId} ` ,
129- ttl: ' 1h' ,
130- });
127+ cacheTag (` user-${ userId} ` );
128+ cacheLife (' 1h' );
131129
132130 return database .getUserProfile (userId);
133131}
@@ -231,27 +229,23 @@ By default, the cached data will be stored for 15 minutes unless `revalidate()`
231229
232230### Setting Cache Parameters
233231
234- When using the ` " use cache" ` directive, you can use ` cacheTag ()` to set cache parameters:
232+ When using the ` " use cache" ` directive, you can use ` cacheTag ()` or ` cacheLife () ` to set cache parameters:
235233
236234` ` ` js
237- import { cacheTag } from ' commandkit' ;
235+ import { cacheTag , cacheLife } from ' commandkit' ;
238236
239237async function fetchData () {
240238 ' use cache' ;
241239
242- cacheTag ({
243- tag: ' user-data' , // cache tag name
244- ttl: ' 1m' , // TTL as string or number (in ms)
245- });
246- // Or just set the tag name
247- cacheTag (' user-data' );
240+ cacheTag (' user-data' ); // cache tag name
241+ cacheLife (' 1m' ); // TTL as string or number (in ms)
248242
249243 const data = await fetch (' https://my-example-api.com/data' );
250244 return data .json ();
251245}
252246` ` `
253247
254- You can also set just the TTL using ` cacheLife` :
248+ You can set the TTL using ` cacheLife` :
255249
256250` ` ` js
257251import { cacheLife } from ' commandkit' ;
0 commit comments