diff --git a/README.md b/README.md
index 9c93d9c..9a18712 100644
--- a/README.md
+++ b/README.md
@@ -55,8 +55,7 @@ To install Sunday.ts, follow these steps:
That's it! You have successfully installed Sunday.ts and are ready to start using it in your Node.js project.
## Features
-- [ ] Multi version
-- [ ] Plugin
+- [x] SearchCache
## 🎈 Usage
@@ -83,6 +82,10 @@ let manager = new Manager({
resumeStatus: true,
},
],
+ cache: {
+ enabled: true,
+ time: 60000,
+ },
clientId: "1234567890",
send(guild_id, payload) {
const guild = client.guilds.cache.get(guild_id);
@@ -146,6 +149,9 @@ client.on("messageCreate", async (message) => {
return message.reply(`enqueuing ${res.tracks[0].title}. ${end}`);
}
});
+manager.on("SearchCacheClear" , (key: string, values) => {
+ console.log(`Cache cleared for ${key} with values: ${values}`);
+});
client.on("raw", (data) => manager.updateVoiceState(data));
client.on("ready" , () => {
manager.init(client.user?.id as string);
diff --git a/example/src/index.ts b/example/src/index.ts
index f1377c9..9daa99c 100644
--- a/example/src/index.ts
+++ b/example/src/index.ts
@@ -20,6 +20,10 @@ let manager = new Manager({
resumeStatus: true,
},
],
+ cache: {
+ enabled: true,
+ time: 60000,
+ },
clientId: "1234567890",
send(guild_id, payload) {
const guild = client.guilds.cache.get(guild_id);
@@ -83,8 +87,8 @@ client.on("messageCreate", async (message) => {
return message.reply(`enqueuing ${res.tracks[0].title}. ${end}`);
}
});
-manager.on("SearchCacheClear" , (key: string, values) => {
- console.log(`Cache cleared for ${key} with values: ${values}`);
+manager.on("SearchCacheClear" , (data) => {
+ console.log(`Cache cleared: ${data}`);
});
client.on("raw", (data) => manager.updateVoiceState(data));
client.on("ready" , () => {
diff --git a/package.json b/package.json
index 2b7776f..10e920e 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "sunday.ts",
"main": "dist/index.js",
"types": "dist/index.d.ts",
- "version": "1.0.11-indev",
+ "version": "1.0.12-indev",
"description": "Sunday a lavalink wrapper",
"license": "MIT",
"author": "FAYStarNext",
diff --git a/src/structures/Manager.ts b/src/structures/Manager.ts
index edbcb0e..e34b02d 100644
--- a/src/structures/Manager.ts
+++ b/src/structures/Manager.ts
@@ -136,14 +136,8 @@ export class Manager extends TypedEmitter {
if (this.options.nodes) this.options.nodes.forEach((nodeOptions) => { return new (Structure.get("Node"))(nodeOptions); });
setInterval(() => {
- const searchCacheKeys = this.search_cache.keys();
- const searchCacheValues = this.search_cache.values();
- const firstKey = searchCacheKeys.next().value;
- const firstValue = searchCacheValues.next().value;
- if (firstKey && firstValue) {
- const searchResultString = JSON.stringify(firstValue);
- this.emit("SearchCacheClear", firstKey, searchResultString);
- }
+ if (this.search_cache.clear() === undefined) return;
+ this.emit("SearchCacheClear", this.search_cache.values().next().value);
this.search_cache.clear();
}, this.options.cache?.time || 10000);
}
@@ -240,7 +234,7 @@ export class Manager extends TypedEmitter {
}
}
}
- if (res.loadType === "search" || "track") this.search_cache.set(code, result);
+ if (options.cache !== false && this.options.cache.enabled !== false) if (res.loadType === "search" || "track") this.search_cache.set(code, result);
return result;
} catch (err) {
throw new Error(err);
@@ -445,7 +439,7 @@ export interface ManagerOptions {
replaceYouTubeCredentials?: boolean;
cache?: {
/** Whether to enable cache. */
- enable: boolean;
+ enabled: boolean;
/** Clear cache every second */
time: number;
}
@@ -506,7 +500,7 @@ export interface PlaylistData {
}
export interface ManagerEvents {
- SearchCacheClear: (key: string, values: SearchResult | unknown) => void;
+ SearchCacheClear: (data: string) => void;
NodeCreate: (node: Node) => void;
NodeDestroy: (node: Node) => void;
NodeConnect: (node: Node) => void;