소스 검색

add better type

Abhinav 2 년 전
부모
커밋
c0b8c9f62b
2개의 변경된 파일7개의 추가작업 그리고 1개의 파일을 삭제
  1. 2 1
      src/services/diskCache.ts
  2. 5 0
      src/types/cache.ts

+ 2 - 1
src/services/diskCache.ts

@@ -2,10 +2,11 @@ import DiskLRUService from '../services/diskLRU';
 import crypto from 'crypto';
 import { existsSync, readFile, writeFile, unlink } from 'promise-fs';
 import path from 'path';
+import { LimitedCache } from '../types/cache';
 
 const MAX_CACHE_SIZE = 1000 * 1000 * 1000; // 1GB
 
-export class DiskCache {
+export class DiskCache implements LimitedCache {
     constructor(private cacheBucketDir: string) {}
 
     async put(cacheKey: string, response: Response): Promise<void> {

+ 5 - 0
src/types/cache.ts

@@ -0,0 +1,5 @@
+export interface LimitedCache {
+    match: (key: string) => Promise<Response>;
+    put: (key: string, data: Response) => Promise<void>;
+    delete: (key: string) => Promise<boolean>;
+}