mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-03 05:26:07 +00:00
feat: cache callback, actually disable cache when disabledCache is true
(#263)
* feat: cache callback, actually disable cache when disabledCache is "true" * fix: types
This commit is contained in:
parent
8cc495a4db
commit
ead838637c
@ -193,12 +193,41 @@ export class BaseClient {
|
|||||||
this.rest = rest;
|
this.rest = rest;
|
||||||
}
|
}
|
||||||
if (cache) {
|
if (cache) {
|
||||||
|
const caches: (keyof Cache['disabledCache'])[] = [
|
||||||
|
'bans',
|
||||||
|
'channels',
|
||||||
|
'emojis',
|
||||||
|
'guilds',
|
||||||
|
'members',
|
||||||
|
'messages',
|
||||||
|
'onPacket',
|
||||||
|
'overwrites',
|
||||||
|
'presences',
|
||||||
|
'roles',
|
||||||
|
'stageInstances',
|
||||||
|
'stickers',
|
||||||
|
'threads',
|
||||||
|
'users',
|
||||||
|
'voiceStates',
|
||||||
|
];
|
||||||
|
let disabledCache: Partial<Record<keyof Cache['disabledCache'], boolean>> = this.cache?.disabledCache ?? {};
|
||||||
|
|
||||||
|
if (typeof cache.disabledCache === 'boolean') {
|
||||||
|
for (const i of caches) {
|
||||||
|
disabledCache[i] = cache.disabledCache;
|
||||||
|
}
|
||||||
|
} else if (typeof cache.disabledCache === 'function') {
|
||||||
|
for (const i of caches) {
|
||||||
|
disabledCache[i] = cache.disabledCache(i);
|
||||||
|
}
|
||||||
|
} else if (typeof cache.disabledCache === 'object') {
|
||||||
|
disabledCache = cache.disabledCache;
|
||||||
|
}
|
||||||
|
|
||||||
this.cache = new Cache(
|
this.cache = new Cache(
|
||||||
this.cache?.intents ?? 0,
|
this.cache?.intents ?? 0,
|
||||||
cache?.adapter ?? this.cache?.adapter ?? new MemoryAdapter(),
|
cache?.adapter ?? this.cache?.adapter ?? new MemoryAdapter(),
|
||||||
(typeof cache.disabledCache === 'boolean' ? { onPacket: cache.disabledCache } : cache.disabledCache) ??
|
disabledCache,
|
||||||
this.cache?.disabledCache ??
|
|
||||||
[],
|
|
||||||
this,
|
this,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -527,7 +556,10 @@ export type RuntimeConfig = OmitInsert<
|
|||||||
|
|
||||||
export interface ServicesOptions {
|
export interface ServicesOptions {
|
||||||
rest?: ApiHandler;
|
rest?: ApiHandler;
|
||||||
cache?: { adapter?: Adapter; disabledCache?: true | Cache['disabledCache'] };
|
cache?: {
|
||||||
|
adapter?: Adapter;
|
||||||
|
disabledCache?: boolean | Cache['disabledCache'] | ((cacheType: keyof Cache['disabledCache']) => boolean);
|
||||||
|
};
|
||||||
langs?: {
|
langs?: {
|
||||||
default?: string;
|
default?: string;
|
||||||
aliases?: Record<string, LocaleString[]>;
|
aliases?: Record<string, LocaleString[]>;
|
||||||
|
@ -16,6 +16,9 @@ export interface ExtendContext {}
|
|||||||
export interface ExtraProps {}
|
export interface ExtraProps {}
|
||||||
export interface UsingClient extends BaseClient {}
|
export interface UsingClient extends BaseClient {}
|
||||||
export type ParseClient<T extends BaseClient> = T;
|
export type ParseClient<T extends BaseClient> = T;
|
||||||
|
export type ParseGlobalMiddlewares<T extends Record<string, MiddlewareContext>> = {
|
||||||
|
[K in keyof T]: MetadataMiddleware<T[K]>;
|
||||||
|
};
|
||||||
export interface InternalOptions {}
|
export interface InternalOptions {}
|
||||||
export interface CustomStructures {}
|
export interface CustomStructures {}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user