1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = exports.SubCache = exports.CacheController = void 0;
- var _AdaptableController = _interopRequireDefault(require("./AdaptableController"));
- var _CacheAdapter = _interopRequireDefault(require("../Adapters/Cache/CacheAdapter"));
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
- const KEY_SEPARATOR_CHAR = ':';
- function joinKeys(...keys) {
- return keys.join(KEY_SEPARATOR_CHAR);
- }
- class SubCache {
- constructor(prefix, cacheController, ttl) {
- this.prefix = prefix;
- this.cache = cacheController;
- this.ttl = ttl;
- }
- get(key) {
- const cacheKey = joinKeys(this.prefix, key);
- return this.cache.get(cacheKey);
- }
- put(key, value, ttl) {
- const cacheKey = joinKeys(this.prefix, key);
- return this.cache.put(cacheKey, value, ttl);
- }
- del(key) {
- const cacheKey = joinKeys(this.prefix, key);
- return this.cache.del(cacheKey);
- }
- clear() {
- return this.cache.clear();
- }
- }
- exports.SubCache = SubCache;
- class CacheController extends _AdaptableController.default {
- constructor(adapter, appId, options = {}) {
- super(adapter, appId, options);
- this.role = new SubCache('role', this);
- this.user = new SubCache('user', this);
- this.graphQL = new SubCache('graphQL', this);
- }
- get(key) {
- const cacheKey = joinKeys(this.appId, key);
- return this.adapter.get(cacheKey).then(null, () => Promise.resolve(null));
- }
- put(key, value, ttl) {
- const cacheKey = joinKeys(this.appId, key);
- return this.adapter.put(cacheKey, value, ttl);
- }
- del(key) {
- const cacheKey = joinKeys(this.appId, key);
- return this.adapter.del(cacheKey);
- }
- clear() {
- return this.adapter.clear();
- }
- expectedAdapterType() {
- return _CacheAdapter.default;
- }
- }
- exports.CacheController = CacheController;
- var _default = exports.default = CacheController;
|