UNPKG

serverless-offline-edge-lambda

Version:

A plugin for the Serverless Framework that simulates the behavior of AWS CloudFront Edge Lambdas while developing offline.

46 lines 2.03 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CacheService = void 0; const flat_cache_1 = __importDefault(require("flat-cache")); const constants_1 = require("../constants"); class CacheService { constructor(cacheDir) { this.cacheDir = cacheDir; this.cache = flat_cache_1.default.load(constants_1.CacheId, cacheDir); } retrieveFromCache(event) { const { request } = event.Records[0].cf; const { uri } = request; return this.cache.getKey(uri); } saveToCache(event) { const { request } = event.Records[0].cf; const { uri } = request; const { body } = event.Records[0].cf.response; this.cache.setKey(uri, body); this.cache.save(); } purge() { return __awaiter(this, void 0, void 0, function* () { flat_cache_1.default.clearCacheById(constants_1.CacheId); // FIXME Workaround. Bug in flat-cache clear methods. Object.entries(this.cache.all()).forEach(entry => { this.cache.removeKey(entry[0]); }); }); } } exports.CacheService = CacheService; //# sourceMappingURL=cache.service.js.map