added new cache delete api
This commit is contained in:
parent
98c4d3c111
commit
ada9b4ace9
1 changed files with 10 additions and 1 deletions
|
@ -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
|
||||||
|
|
Loading…
Add table
Reference in a new issue