added new cache delete api

This commit is contained in:
Abhinav 2022-08-12 13:29:35 +05:30
parent 98c4d3c111
commit ada9b4ace9

View file

@ -1,6 +1,6 @@
import DiskLRUService from '../services/diskLRU'; import DiskLRUService from '../services/diskLRU';
import crypto from 'crypto'; import crypto from 'crypto';
import { existsSync, readFile, writeFile } from 'promise-fs'; import { existsSync, readFile, writeFile, unlink } from 'promise-fs';
import path from 'path'; import path from 'path';
const MAX_CACHE_SIZE = 1000 * 1000 * 1000; // 1GB const MAX_CACHE_SIZE = 1000 * 1000 * 1000; // 1GB
@ -29,6 +29,15 @@ export class DiskCache {
return undefined; return undefined;
} }
} }
async delete(cacheKey: string): Promise<boolean> {
const cachePath = getAssetCachePath(this.cacheBucketDir, cacheKey);
if (existsSync(cachePath)) {
await unlink(cachePath);
return true;
} else {
return false;
}
}
} }
function getAssetCachePath(cacheDir: string, cacheKey: string) { function getAssetCachePath(cacheDir: string, cacheKey: string) {
// hashing the key to prevent illegal filenames // hashing the key to prevent illegal filenames