UNPKG

@anglr/rest

Version:

Angular module representing rest services

26 lines 898 B
import { isPresent } from '@jscrpt/common'; import { CacheMiddleware } from '../middlewares'; //Object storing response cache itself //It caches request urls to response data const responseCache = {}; /** * Results of requests are cached in javascript memory */ export function Cache() { return function (_target, _propertyKey, descriptor) { const descr = descriptor; descr.middlewareTypes.push(CacheMiddleware); descr.getCachedResponse = (request) => { if (isPresent(responseCache[request.urlWithParams])) { return responseCache[request.urlWithParams]; } return null; }; descr.saveResponseToCache = (request, response) => { responseCache[request.urlWithParams] = response; return response; }; return descr; }; } //# sourceMappingURL=cache.decorator.js.map