Move core files into new folder
This commit is contained in:
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) Contributors to the Suwayomi project
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
export class CustomCache {
|
||||
private keyToResponseMap = new Map<string, unknown>();
|
||||
|
||||
private keyToFetchTimestampMap = new Map<string, number>();
|
||||
|
||||
public readonly createKeyFn = (endpoint: string, data: unknown): string => `${endpoint}_${JSON.stringify(data)}`;
|
||||
|
||||
constructor(createKeyFn?: (endpoint: string, data: unknown) => string) {
|
||||
this.createKeyFn = createKeyFn ?? this.createKeyFn;
|
||||
}
|
||||
|
||||
public getKeyFor(key: string, data: unknown): string {
|
||||
return this.createKeyFn(key, data);
|
||||
}
|
||||
|
||||
public cacheResponse(endpoint: string, data: unknown, response: unknown) {
|
||||
const createdKey = this.getKeyFor(endpoint, data);
|
||||
this.keyToFetchTimestampMap.set(createdKey, Date.now());
|
||||
this.keyToResponseMap.set(createdKey, response);
|
||||
}
|
||||
|
||||
public getFetchTimestampFor(endpoint: string, data: unknown): number | undefined {
|
||||
const key = this.getKeyFor(endpoint, data);
|
||||
return this.keyToFetchTimestampMap.get(key);
|
||||
}
|
||||
|
||||
public getResponseFor<Response = any>(endpoint: string, data: unknown, ttl?: number): Response | undefined {
|
||||
const key = this.getKeyFor(endpoint, data);
|
||||
|
||||
const isTtlReached = ttl && Date.now() - (this.getFetchTimestampFor(endpoint, data) ?? 0) >= ttl;
|
||||
if (isTtlReached) {
|
||||
this.keyToResponseMap.delete(key);
|
||||
}
|
||||
|
||||
return this.keyToResponseMap.get(key) as Response;
|
||||
}
|
||||
|
||||
public getAllKeys(): string[] {
|
||||
return [...this.keyToResponseMap.keys()];
|
||||
}
|
||||
|
||||
public getMatchingKeys(regex: RegExp): string[] {
|
||||
return this.getAllKeys().filter((key) => !!regex.exec(key));
|
||||
}
|
||||
|
||||
public clearFor(...keys: string[]) {
|
||||
keys.forEach((key) => {
|
||||
this.keyToResponseMap.delete(key);
|
||||
this.keyToFetchTimestampMap.delete(key);
|
||||
});
|
||||
}
|
||||
|
||||
public clear(): void {
|
||||
this.keyToResponseMap.clear();
|
||||
this.keyToFetchTimestampMap.clear();
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
import { AppStorage } from '@/util/AppStorage.ts';
|
||||
import { AppStorage } from '@/lib/AppStorage.ts';
|
||||
|
||||
export abstract class BaseClient<Client, ClientConfig, Fetcher> {
|
||||
protected abstract client: Client;
|
||||
|
||||
@@ -276,7 +276,7 @@ import {
|
||||
UPDATE_LIBRARY_MANGAS,
|
||||
} from '@/lib/graphql/mutations/UpdaterMutation.ts';
|
||||
import { GET_LAST_UPDATE_TIMESTAMP, GET_UPDATE_STATUS } from '@/lib/graphql/queries/UpdaterQuery.ts';
|
||||
import { CustomCache } from '@/lib/requests/CustomCache.ts';
|
||||
import { CustomCache } from '@/lib/CustomCache.ts';
|
||||
import { RESTORE_BACKUP } from '@/lib/graphql/mutations/BackupMutation.ts';
|
||||
import { GET_RESTORE_STATUS, VALIDATE_BACKUP } from '@/lib/graphql/queries/BackupQuery.ts';
|
||||
import { DOWNLOAD_STATUS_SUBSCRIPTION } from '@/lib/graphql/subscriptions/DownloaderSubscription.ts';
|
||||
@@ -287,7 +287,7 @@ import { CLEAR_SERVER_CACHE } from '@/lib/graphql/mutations/ImageMutation.ts';
|
||||
import { RESET_WEBUI_UPDATE_STATUS, UPDATE_WEBUI } from '@/lib/graphql/mutations/ServerInfoMutation.ts';
|
||||
import { WEBUI_UPDATE_SUBSCRIPTION } from '@/lib/graphql/subscriptions/ServerInfoSubscription.ts';
|
||||
import { GET_DOWNLOAD_STATUS } from '@/lib/graphql/queries/DownloaderQuery.ts';
|
||||
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
|
||||
import { defaultPromiseErrorHandler } from '@/lib/DefaultPromiseErrorHandler.ts';
|
||||
import { Queue, QueuePriority } from '@/lib/Queue.ts';
|
||||
import { TRACKER_SEARCH } from '@/lib/graphql/queries/TrackerQuery.ts';
|
||||
import {
|
||||
@@ -305,7 +305,7 @@ import { DOWNLOAD_STATUS_FIELDS } from '@/lib/graphql/fragments/DownloadFragment
|
||||
import { EXTENSION_LIST_FIELDS } from '@/lib/graphql/fragments/ExtensionFragments.ts';
|
||||
import { MANGA_BASE_FIELDS, MANGA_META_FIELDS } from '@/lib/graphql/fragments/MangaFragments.ts';
|
||||
import { MangaIdInfo } from '@/lib/data/Mangas.ts';
|
||||
import { GLOBAL_METADATA } from '@/lib/graphql/fragments/Fragments';
|
||||
import { GLOBAL_METADATA } from '@/lib/graphql/fragments/Fragments.ts';
|
||||
import { CATEGORY_META_FIELDS } from '@/lib/graphql/fragments/CategoryFragments.ts';
|
||||
import { SOURCE_META_FIELDS } from '@/lib/graphql/fragments/SourceFragments.ts';
|
||||
import { CHAPTER_META_FIELDS } from '@/lib/graphql/fragments/ChapterFragments.ts';
|
||||
Reference in New Issue
Block a user