@@ -44,10 +44,10 @@ Let's build a simple XP system using CommandKit's caching feature. We'll create:
44
44
### XP Command
45
45
46
46
``` js
47
- import { SlashCommandProps , CommandData , cacheTag } from ' commandkit' ;
47
+ import { SlashCommand , CommandData , cacheTag } from ' commandkit' ;
48
48
import { database } from ' ../database' ;
49
49
50
- export const data = {
50
+ export const command : CommandData = {
51
51
name: ' xp' ,
52
52
description: ' Check your XP' ,
53
53
};
@@ -63,7 +63,7 @@ async function getUserXP(guildId, userId) {
63
63
return xp;
64
64
}
65
65
66
- export async function run ({ interaction }) {
66
+ export const chatInput : SlashCommand = async ({ interaction }) => {
67
67
await interaction .deferReply ();
68
68
69
69
const xp = await getUserXP (interaction .guildId , interaction .user .id );
@@ -124,10 +124,8 @@ const fetchPokemon = cache(
124
124
async function fetchUserProfile (userId ) {
125
125
' use cache' ;
126
126
127
- cacheTag ({
128
- tag: ` user-${ userId} ` ,
129
- ttl: ' 1h' ,
130
- });
127
+ cacheTag (` user-${ userId} ` );
128
+ cacheLife (' 1h' );
131
129
132
130
return database .getUserProfile (userId);
133
131
}
@@ -231,27 +229,23 @@ By default, the cached data will be stored for 15 minutes unless `revalidate()`
231
229
232
230
### Setting Cache Parameters
233
231
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:
235
233
236
234
` ` ` js
237
- import { cacheTag } from ' commandkit' ;
235
+ import { cacheTag , cacheLife } from ' commandkit' ;
238
236
239
237
async function fetchData () {
240
238
' use cache' ;
241
239
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)
248
242
249
243
const data = await fetch (' https://my-example-api.com/data' );
250
244
return data .json ();
251
245
}
252
246
` ` `
253
247
254
- You can also set just the TTL using ` cacheLife` :
248
+ You can set the TTL using ` cacheLife` :
255
249
256
250
` ` ` js
257
251
import { cacheLife } from ' commandkit' ;
0 commit comments