diff options
| author | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-09-23 09:48:38 +0200 |
|---|---|---|
| committer | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-09-23 09:48:38 +0200 |
| commit | 09596c3c5a6a2a44675f170106bb38746229e02a (patch) | |
| tree | 763d1b710dc5f2fcab920ac6ab2c555cee4d6342 /src/scripts/controllers/connection/cache.ts | |
| parent | 057952b0bacc6e963c74bb1bbebbcccd6174a75c (diff) | |
Remove old frontend
Diffstat (limited to 'src/scripts/controllers/connection/cache.ts')
| -rw-r--r-- | src/scripts/controllers/connection/cache.ts | 85 |
1 files changed, 0 insertions, 85 deletions
diff --git a/src/scripts/controllers/connection/cache.ts b/src/scripts/controllers/connection/cache.ts deleted file mode 100644 index c1c47c2d..00000000 --- a/src/scripts/controllers/connection/cache.ts +++ /dev/null @@ -1,85 +0,0 @@ -export enum CacheStatus { - MISS, - FETCHING, - HIT, - NOT_CACHABLE -} - - -interface ICachableObject { - status: CacheStatus; - object: any; - callbacks: any[]; -} - - -export class CacheController { - private static CACHABLE_ROUTES = [ - "/specifications/psus/{id}", - "/specifications/cooling-items/{id}", - "/specifications/cpus/{id}", - "/specifications/gpus/{id}", - "/specifications/memories/{id}", - "/specifications/storages/{id}", - "/specifications/failure-models/{id}", - ]; - - // Maps every route name to a map of IDs => objects - private routeCaches: { [keys: string]: { [keys: number]: ICachableObject } }; - - - constructor() { - this.routeCaches = {}; - - CacheController.CACHABLE_ROUTES.forEach((routeName: string) => { - this.routeCaches[routeName] = {}; - }) - } - - public checkCache(request: IRequest): CacheStatus { - if (request.method === "GET" && CacheController.CACHABLE_ROUTES.indexOf(request.path) !== -1) { - if (this.routeCaches[request.path][request.parameters.path["id"]] === undefined) { - this.routeCaches[request.path][request.parameters.path["id"]] = { - status: CacheStatus.MISS, - object: null, - callbacks: [] - }; - return CacheStatus.MISS; - } else { - return this.routeCaches[request.path][request.parameters.path["id"]].status; - } - } else { - return CacheStatus.NOT_CACHABLE; - } - } - - public fetchFromCache(request: IRequest): any { - return this.routeCaches[request.path][request.parameters.path["id"]].object; - } - - public setToFetching(request: IRequest): void { - this.routeCaches[request.path][request.parameters.path["id"]].status = CacheStatus.FETCHING; - } - - public onFetch(request: IRequest, response: IResponse): any { - const pathWithoutVersion = request.path.replace(/\/v\d+/, ""); - this.routeCaches[pathWithoutVersion][request.parameters.path["id"]].status = CacheStatus.HIT; - this.routeCaches[pathWithoutVersion][request.parameters.path["id"]].object = response.content; - - this.routeCaches[pathWithoutVersion][request.parameters.path["id"]].callbacks.forEach((callback) => { - callback({ - status: { - code: 200 - }, - content: response.content, - id: request.id - }); - }); - - this.routeCaches[pathWithoutVersion][request.parameters.path["id"]].callbacks = []; - } - - public registerCallback(request: IRequest, callback): any { - this.routeCaches[request.path][request.parameters.path["id"]].callbacks.push(callback); - } -} |
