Forráskód Böngészése

added new cache delete api

Abhinav 2 éve
szülő
commit
ada9b4ace9
1 módosított fájl, 10 hozzáadás és 1 törlés
  1. 10 1
      src/services/diskCache.ts

+ 10 - 1
src/services/diskCache.ts

@@ -1,6 +1,6 @@
 import DiskLRUService from '../services/diskLRU';
 import crypto from 'crypto';
-import { existsSync, readFile, writeFile } from 'promise-fs';
+import { existsSync, readFile, writeFile, unlink } from 'promise-fs';
 import path from 'path';
 
 const MAX_CACHE_SIZE = 1000 * 1000 * 1000; // 1GB
@@ -29,6 +29,15 @@ export class DiskCache {
             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) {
     // hashing the key to prevent illegal filenames