fix(core): Fix S3 cache manager methods for better path encoding consistency

This commit is contained in:
2024-11-26 22:41:10 +01:00
parent 69b2aa7fb8
commit 8bf1af08d3
8 changed files with 2632 additions and 1796 deletions

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/levelcache',
version: '3.1.0',
version: '3.1.1',
description: 'A versatile caching solution offering multi-level storage utilizing memory, disk, and Amazon S3 for efficient data management and backup.'
}

View File

@ -42,16 +42,18 @@ export class CacheS3Manager extends AbstractCache {
}
public async retrieveCacheEntryByKey(keyArg: string): Promise<CacheEntry> {
const jsonFileString = (await this.s3CacheDir.fastGet(encodeURIComponent(keyArg))).toString();
const jsonFileString = (await this.s3CacheDir.fastGet({
path: encodeURIComponent(keyArg),
})).toString();
const cacheEntry = CacheEntry.fromStorageJsonString(jsonFileString);
return cacheEntry;
}
public async storeCacheEntryByKey(keyArg: string, cacheEntryArg: CacheEntry) {
await this.s3CacheDir.fastStore(
encodeURIComponent(keyArg),
cacheEntryArg.toStorageJsonString()
);
await this.s3CacheDir.fastPut({
path: encodeURIComponent(keyArg),
contents: cacheEntryArg.toStorageJsonString()
});
}
public async checkKeyPresence(keyArg: string): Promise<boolean> {
@ -66,7 +68,9 @@ export class CacheS3Manager extends AbstractCache {
public async deleteCacheEntryByKey(keyArg: string) {
if (this.status === 'active') {
await this.s3CacheDir.fastRemove(encodeURIComponent(keyArg));
await this.s3CacheDir.fastRemove({
path: encodeURIComponent(keyArg),
});
}
}
@ -76,6 +80,8 @@ export class CacheS3Manager extends AbstractCache {
public async cleanOutdated() {}
public async cleanAll() {
await this.s3CacheDir.deleteWithAllContents();
await this.s3CacheDir.delete({
mode: 'permanent',
});
}
}