lavva.exalushome
Version:
Library implementing communication and abstraction layers for ExalusHome system
43 lines • 2.05 kB
JavaScript
import { Api } from '../../Api';
import { Status } from "../../DataFrame";
import { LocalStorageService } from '../LocalStorageService';
import { LoggerService } from '../Logging/LoggerService';
export class WebApiCacheService {
constructor() {
this._log = Api.Get(LoggerService.ServiceName);
WebApiCacheService._localStorageService = Api.Get(LocalStorageService.ServiceName);
}
GetServiceName() {
return WebApiCacheService.ServiceName;
}
GetResourceName(data) {
return `${data.Resource}_${data.Method}`;
}
Cache(data) {
var _a;
if (data.Status !== Status.OK)
return;
this._log.Debug(WebApiCacheService.ServiceName, `Caching request: ${data.Resource} ${data.Method}`);
(_a = WebApiCacheService._localStorageService) === null || _a === void 0 ? void 0 : _a.Save(this.GetServiceName(), this.GetResourceName(data), data);
}
GetCache(data) {
var _a;
let tmp = (_a = WebApiCacheService._localStorageService) === null || _a === void 0 ? void 0 : _a.Read(this.GetServiceName(), this.GetResourceName(data));
if (tmp != null)
this._log.Debug(WebApiCacheService.ServiceName, `Got request response from cache: ${data.Resource} ${data.Method}`);
return tmp;
}
ClearCache() {
var _a;
(_a = WebApiCacheService._localStorageService) === null || _a === void 0 ? void 0 : _a.DropStorage(this.GetServiceName());
this._log.Debug(WebApiCacheService.ServiceName, `Clearing cache for ${this.GetServiceName()}`);
}
Remove(data) {
var _a;
(_a = WebApiCacheService._localStorageService) === null || _a === void 0 ? void 0 : _a.Remove(this.GetServiceName(), this.GetResourceName(data));
this._log.Debug(WebApiCacheService.ServiceName, `Clearing cache for cache: ${data.Resource} ${data.Method}`);
}
}
WebApiCacheService._localStorageService = null;
WebApiCacheService.ServiceName = "WebApiCacheService";
//# sourceMappingURL=WebApiCacheService.js.map