Skip to content
This repository was archived by the owner on Mar 1, 2025. It is now read-only.

Commit

Permalink
Merge pull request #21 from FAYStarNext/dev
Browse files Browse the repository at this point in the history
Edit Options Caches
  • Loading branch information
EvarinDev authored Jul 30, 2024
2 parents 7760417 + e938f4b commit c5f865d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion example/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let manager = new Manager({
resumeStatus: true,
},
],
cache: {
caches: {
enabled: true,
time: 60000,
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "sunday.ts",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"version": "1.0.13-indev",
"version": "1.0.14-indev",
"description": "Sunday a lavalink wrapper",
"license": "MIT",
"author": "FAYStarNext",
Expand Down
18 changes: 10 additions & 8 deletions src/structures/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,13 @@ export class Manager extends TypedEmitter<ManagerEvents> {
}

if (this.options.nodes) this.options.nodes.forEach((nodeOptions) => { return new (Structure.get("Node"))(nodeOptions); });
setInterval(() => {
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);
if (this.options.caches.enabled){
setInterval(() => {
if (this.search_cache.clear() === undefined) return;
this.emit("SearchCacheClear", this.search_cache.values().next().value);
this.search_cache.clear();
}, this.options.caches?.time || 10000);
} else return;
}

/**
Expand Down Expand Up @@ -178,7 +180,7 @@ export class Manager extends TypedEmitter<ManagerEvents> {
let search = _query.query;
let code = this.CheckURL(options.query);
if (!/^https?:\/\//.test(search)) search = `${_source}:${search}`;
if (options.cache !== false && this.options.cache.enabled !== false) {
if (options.cache !== false && this.options.caches.enabled !== false) {
if (this.search_cache.get(code)) return this.search_cache.get(code);
}
try {
Expand Down Expand Up @@ -236,7 +238,7 @@ export class Manager extends TypedEmitter<ManagerEvents> {
}
}
}
if (options.cache !== false && this.options.cache.enabled !== false) if (res.loadType === "search" || "track") this.search_cache.set(code, result);
if (options.cache !== false && this.options.caches.enabled !== false) if (res.loadType === "search" || "track") this.search_cache.set(code, result);
return result;
} catch (err) {
throw new Error(err);
Expand Down Expand Up @@ -439,7 +441,7 @@ export interface ManagerOptions {
defaultSearchPlatform?: SearchPlatform;
/** Whether the YouTube video titles should be replaced if the Author does not exactly match. */
replaceYouTubeCredentials?: boolean;
cache?: {
caches: {
/** Whether to enable cache. */
enabled: boolean;
/** Clear cache every second */
Expand Down
4 changes: 4 additions & 0 deletions test/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ let client = new Manager({
},
],
clientId: "1234567890",
caches: {
enabled: true,
time: 60000,
},
send(guild_id, payload) {
console.log(`Sending payload to guild ${guild_id}: ${JSON.stringify(payload)}`);
},
Expand Down

0 comments on commit c5f865d

Please sign in to comment.