Cache.js 743 B

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. const SPLIT = '%';
  7. class Entity {
  8. constructor(instanceId) {
  9. /** @private Internal cache map. Do not access this directly */
  10. this.cache = new Map();
  11. this.instanceId = instanceId;
  12. }
  13. get(keys) {
  14. return this.cache.get(Array.isArray(keys) ? keys.join(SPLIT) : keys) || null;
  15. }
  16. update(keys, valueFn) {
  17. const path = Array.isArray(keys) ? keys.join(SPLIT) : keys;
  18. const prevValue = this.cache.get(path);
  19. const nextValue = valueFn(prevValue);
  20. if (nextValue === null) {
  21. this.cache.delete(path);
  22. } else {
  23. this.cache.set(path, nextValue);
  24. }
  25. }
  26. }
  27. var _default = exports.default = Entity;