@expo/entity-cache-adapter-local-memory 0.31.0 → 0.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/build/GenericLocalMemoryCacher.d.ts +6 -5
  2. package/build/GenericLocalMemoryCacher.js +14 -5
  3. package/build/GenericLocalMemoryCacher.js.map +1 -1
  4. package/build/LocalMemoryCacheAdapterProvider.d.ts +3 -4
  5. package/build/LocalMemoryCacheAdapterProvider.js +5 -6
  6. package/build/LocalMemoryCacheAdapterProvider.js.map +1 -1
  7. package/build/__tests__/{LocalMemoryCacheAdapter-full-test.js → GenericLocalMemoryCacher-full-test.js} +17 -18
  8. package/build/__tests__/GenericLocalMemoryCacher-full-test.js.map +1 -0
  9. package/build/__tests__/GenericLocalMemoryCacher-test.js +98 -3
  10. package/build/__tests__/GenericLocalMemoryCacher-test.js.map +1 -1
  11. package/build/index.d.ts +0 -1
  12. package/build/index.js +1 -3
  13. package/build/index.js.map +1 -1
  14. package/build/testfixtures/LocalMemoryTestEntity.d.ts +2 -2
  15. package/build/testfixtures/LocalMemoryTestEntity.js +6 -7
  16. package/build/testfixtures/LocalMemoryTestEntity.js.map +1 -1
  17. package/package.json +4 -4
  18. package/src/GenericLocalMemoryCacher.ts +24 -3
  19. package/src/LocalMemoryCacheAdapterProvider.ts +7 -5
  20. package/src/__tests__/{LocalMemoryCacheAdapter-full-test.ts → GenericLocalMemoryCacher-full-test.ts} +33 -32
  21. package/src/__tests__/GenericLocalMemoryCacher-test.ts +115 -1
  22. package/src/index.ts +0 -1
  23. package/src/testfixtures/LocalMemoryTestEntity.ts +6 -8
  24. package/build/LocalMemoryCacheAdapter.d.ts +0 -11
  25. package/build/LocalMemoryCacheAdapter.js +0 -45
  26. package/build/LocalMemoryCacheAdapter.js.map +0 -1
  27. package/build/__tests__/LocalMemoryCacheAdapter-full-test.js.map +0 -1
  28. package/build/__tests__/LocalMemoryCacheAdapter-test.d.ts +0 -1
  29. package/build/__tests__/LocalMemoryCacheAdapter-test.js +0 -104
  30. package/build/__tests__/LocalMemoryCacheAdapter-test.js.map +0 -1
  31. package/src/LocalMemoryCacheAdapter.ts +0 -80
  32. package/src/__tests__/LocalMemoryCacheAdapter-test.ts +0 -107
  33. /package/build/__tests__/{LocalMemoryCacheAdapter-full-test.d.ts → GenericLocalMemoryCacher-full-test.d.ts} +0 -0
@@ -1,11 +1,12 @@
1
- import { CacheLoadResult, IEntityGenericCacher } from '@expo/entity';
1
+ import { CacheLoadResult, EntityConfiguration, IEntityGenericCacher } from '@expo/entity';
2
2
  import LRUCache from 'lru-cache';
3
3
  export declare const DOES_NOT_EXIST_LOCAL_MEMORY_CACHE: unique symbol;
4
- declare type LocalMemoryCacheValue<TFields> = Readonly<TFields> | typeof DOES_NOT_EXIST_LOCAL_MEMORY_CACHE;
5
- export declare type LocalMemoryCache<TFields> = LRUCache<string, LocalMemoryCacheValue<TFields>>;
4
+ type LocalMemoryCacheValue<TFields> = Readonly<TFields> | typeof DOES_NOT_EXIST_LOCAL_MEMORY_CACHE;
5
+ export type LocalMemoryCache<TFields> = LRUCache<string, LocalMemoryCacheValue<TFields>>;
6
6
  export default class GenericLocalMemoryCacher<TFields> implements IEntityGenericCacher<TFields> {
7
+ private readonly entityConfiguration;
7
8
  private readonly localMemoryCache;
8
- constructor(localMemoryCache: LocalMemoryCache<TFields>);
9
+ constructor(entityConfiguration: EntityConfiguration<TFields>, localMemoryCache: LocalMemoryCache<TFields>);
9
10
  static createLRUCache<TFields>(options?: {
10
11
  maxSize?: number;
11
12
  ttlSeconds?: number;
@@ -15,6 +16,6 @@ export default class GenericLocalMemoryCacher<TFields> implements IEntityGeneric
15
16
  cacheManyAsync(objectMap: ReadonlyMap<string, Readonly<TFields>>): Promise<void>;
16
17
  cacheDBMissesAsync(keys: readonly string[]): Promise<void>;
17
18
  invalidateManyAsync(keys: readonly string[]): Promise<void>;
18
- makeCacheKey(parts: string[]): string;
19
+ makeCacheKey<N extends keyof TFields>(fieldName: N, fieldValue: NonNullable<TFields[N]>): string;
19
20
  }
20
21
  export {};
@@ -5,21 +5,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.DOES_NOT_EXIST_LOCAL_MEMORY_CACHE = void 0;
7
7
  const entity_1 = require("@expo/entity");
8
+ const invariant_1 = __importDefault(require("invariant"));
8
9
  const lru_cache_1 = __importDefault(require("lru-cache"));
9
10
  // Sentinel value we store in local memory to negatively cache a database miss.
10
11
  // The sentinel value is distinct from any (positively) cached value.
11
12
  exports.DOES_NOT_EXIST_LOCAL_MEMORY_CACHE = Symbol('doesNotExist');
12
13
  class GenericLocalMemoryCacher {
13
- constructor(localMemoryCache) {
14
+ constructor(entityConfiguration, localMemoryCache) {
15
+ this.entityConfiguration = entityConfiguration;
14
16
  this.localMemoryCache = localMemoryCache;
15
17
  }
16
18
  static createLRUCache(options = {}) {
17
- var _a, _b;
18
19
  const DEFAULT_LRU_CACHE_MAX_AGE_SECONDS = 10;
19
20
  const DEFAULT_LRU_CACHE_SIZE = 10000;
20
- const maxAgeSeconds = (_a = options.ttlSeconds) !== null && _a !== void 0 ? _a : DEFAULT_LRU_CACHE_MAX_AGE_SECONDS;
21
+ const maxAgeSeconds = options.ttlSeconds ?? DEFAULT_LRU_CACHE_MAX_AGE_SECONDS;
21
22
  return new lru_cache_1.default({
22
- max: (_b = options.maxSize) !== null && _b !== void 0 ? _b : DEFAULT_LRU_CACHE_SIZE,
23
+ max: options.maxSize ?? DEFAULT_LRU_CACHE_SIZE,
23
24
  length: (value) => (value === exports.DOES_NOT_EXIST_LOCAL_MEMORY_CACHE ? 0 : 1),
24
25
  maxAge: maxAgeSeconds * 1000, // convert to ms
25
26
  });
@@ -68,7 +69,15 @@ class GenericLocalMemoryCacher {
68
69
  this.localMemoryCache.del(key);
69
70
  }
70
71
  }
71
- makeCacheKey(parts) {
72
+ makeCacheKey(fieldName, fieldValue) {
73
+ const columnName = this.entityConfiguration.entityToDBFieldsKeyMapping.get(fieldName);
74
+ (0, invariant_1.default)(columnName, `database field mapping missing for ${String(fieldName)}`);
75
+ const parts = [
76
+ this.entityConfiguration.tableName,
77
+ `${this.entityConfiguration.cacheKeyVersion}`,
78
+ columnName,
79
+ String(fieldValue),
80
+ ];
72
81
  const delimiter = ':';
73
82
  const escapedParts = parts.map((part) => part.replace('\\', '\\\\').replace(delimiter, `\\${delimiter}`));
74
83
  return escapedParts.join(delimiter);
@@ -1 +1 @@
1
- {"version":3,"file":"GenericLocalMemoryCacher.js","sourceRoot":"","sources":["../src/GenericLocalMemoryCacher.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAkF;AAClF,0DAAiC;AAEjC,+EAA+E;AAC/E,qEAAqE;AACxD,QAAA,iCAAiC,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AAIxE,MAAqB,wBAAwB;IAC3C,YAA6B,gBAA2C;QAA3C,qBAAgB,GAAhB,gBAAgB,CAA2B;IAAG,CAAC;IAE5E,MAAM,CAAC,cAAc,CACnB,UAAqD,EAAE;;QAEvD,MAAM,iCAAiC,GAAG,EAAE,CAAC;QAC7C,MAAM,sBAAsB,GAAG,KAAK,CAAC;QACrC,MAAM,aAAa,GAAG,MAAA,OAAO,CAAC,UAAU,mCAAI,iCAAiC,CAAC;QAC9E,OAAO,IAAI,mBAAQ,CAAyC;YAC1D,GAAG,EAAE,MAAA,OAAO,CAAC,OAAO,mCAAI,sBAAsB;YAC9C,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,yCAAiC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACxE,MAAM,EAAE,aAAa,GAAG,IAAI,EAAE,gBAAgB;SAC/C,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,eAAe;QACpB,OAAO,IAAI,mBAAQ,CAAyC;YAC1D,GAAG,EAAE,CAAC;YACN,MAAM,EA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AAI,EAAE;YACtB,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;SAChC;IACH,CAAC;IAEM,YAAY,CACjB,SAAY,EACZ,UAAmC;QAEnC,MAAM,UAAU,GAAG,IAAI,CAAC,mBAAmB,CAAC,0BAA0B,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACtF,IAAA,mBAAS,EAAC,UAAU,EAAE,sCAAsC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;QACjF,MAAM,KAAK,GAAG;YACZ,IAAI,CAAC,mBAAmB,CAAC,SAAS;YAClC,GAAG,IAAI,CAAC,mBAAmB,CAAC,eAAe,EAAE;YAC7C,UAAU;YACV,MAAM,CAAC,UAAU,CAAC;SACnB,CAAC;QAEF,MAAM,SAAS,GAAG,GAAG,CAAC;QACtB,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACtC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,SAAS,EAAE,CAAC,CAChE,CAAC;QACF,OAAO,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC;CACF;AAvFD,2CAuFC"}
@@ -1,13 +1,12 @@
1
- import { EntityCacheAdapter, EntityConfiguration, IEntityCacheAdapterProvider } from '@expo/entity';
2
- import LocalMemoryCacheAdapter from './LocalMemoryCacheAdapter';
1
+ import { IEntityCacheAdapter, EntityConfiguration, IEntityCacheAdapterProvider } from '@expo/entity';
3
2
  export default class LocalMemoryCacheAdapterProvider implements IEntityCacheAdapterProvider {
4
3
  private readonly localMemoryCacheCreator;
5
- static localMemoryCacheAdapterMap: Map<string, LocalMemoryCacheAdapter<any>>;
4
+ private static localMemoryCacheAdapterMap;
6
5
  static getNoOpProvider(): IEntityCacheAdapterProvider;
7
6
  static getProvider(options?: {
8
7
  maxSize?: number;
9
8
  ttlSeconds?: number;
10
9
  }): IEntityCacheAdapterProvider;
11
10
  private constructor();
12
- getCacheAdapter<TFields>(entityConfiguration: EntityConfiguration<TFields>): EntityCacheAdapter<TFields>;
11
+ getCacheAdapter<TFields>(entityConfiguration: EntityConfiguration<TFields>): IEntityCacheAdapter<TFields>;
13
12
  }
@@ -5,25 +5,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const entity_1 = require("@expo/entity");
7
7
  const GenericLocalMemoryCacher_1 = __importDefault(require("./GenericLocalMemoryCacher"));
8
- const LocalMemoryCacheAdapter_1 = __importDefault(require("./LocalMemoryCacheAdapter"));
9
8
  class LocalMemoryCacheAdapterProvider {
10
- constructor(localMemoryCacheCreator) {
11
- this.localMemoryCacheCreator = localMemoryCacheCreator;
12
- }
13
9
  static getNoOpProvider() {
14
10
  return new LocalMemoryCacheAdapterProvider(() => GenericLocalMemoryCacher_1.default.createNoOpCache());
15
11
  }
16
12
  static getProvider(options = {}) {
17
13
  return new LocalMemoryCacheAdapterProvider(() => GenericLocalMemoryCacher_1.default.createLRUCache(options));
18
14
  }
15
+ constructor(localMemoryCacheCreator) {
16
+ this.localMemoryCacheCreator = localMemoryCacheCreator;
17
+ }
19
18
  getCacheAdapter(entityConfiguration) {
20
19
  return (0, entity_1.computeIfAbsent)(LocalMemoryCacheAdapterProvider.localMemoryCacheAdapterMap, entityConfiguration.tableName, () => {
21
20
  const localMemoryCache = this.localMemoryCacheCreator();
22
- return new LocalMemoryCacheAdapter_1.default(entityConfiguration, localMemoryCache);
21
+ return new entity_1.GenericEntityCacheAdapter(new GenericLocalMemoryCacher_1.default(entityConfiguration, localMemoryCache));
23
22
  });
24
23
  }
25
24
  }
26
- exports.default = LocalMemoryCacheAdapterProvider;
27
25
  // local memory cache adapters should be shared/reused across requests
28
26
  LocalMemoryCacheAdapterProvider.localMemoryCacheAdapterMap = new Map();
27
+ exports.default = LocalMemoryCacheAdapterProvider;
29
28
  //# sourceMappingURL=LocalMemoryCacheAdapterProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"LocalMemoryCacheAdapterProvider.js","sourceRoot":"","sources":["../src/LocalMemoryCacheAdapterProvider.ts"],"names":[],"mappings":";;;;;AAAA,yCAKsB;AAEtB,0FAAwF;AACxF,wFAAgE;AAEhE,MAAqB,+BAA+B;IAkBlD,YACmB,uBAAiE;QAAjE,4BAAuB,GAAvB,uBAAuB,CAA0C;IACjF,CAAC;IAhBJ,MAAM,CAAC,eAAe;QACpB,OAAO,IAAI,+BAA+B,CAAC,GAAY,EAAE,CACvD,kCAAwB,CAAC,eAAe,EAAW,CACpD,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,WAAW,CAChB,UAAqD,EAAE;QAEvD,OAAO,IAAI,+BAA+B,CAAC,GAAY,EAAE,CACvD,kCAAwB,CAAC,cAAc,CAAU,OAAO,CAAC,CAC1D,CAAC;IACJ,CAAC;IAMM,eAAe,CACpB,mBAAiD;QAEjD,OAAO,IAAA,wBAAe,EACpB,+BAA+B,CAAC,0BAA0B,EAC1D,mBAAmB,CAAC,SAAS,EAC7B,GAAG,EAAE;YACH,MAAM,gBAAgB,GAAG,IAAI,CAAC,uBAAuB,EAAW,CAAC;YACjE,OAAO,IAAI,iCAAuB,CAAC,mBAAmB,EAAE,gBAAgB,CAAC,CAAC;QAC5E,CAAC,CACF,CAAC;IACJ,CAAC;;AAjCH,kDAkCC;AAjCC,sEAAsE;AAC/D,0DAA0B,GAAG,IAAI,GAAG,EAAwC,CAAC"}
1
+ {"version":3,"file":"LocalMemoryCacheAdapterProvider.js","sourceRoot":"","sources":["../src/LocalMemoryCacheAdapterProvider.ts"],"names":[],"mappings":";;;;;AAAA,yCAMsB;AAEtB,0FAAwF;AAExF,MAAqB,+BAA+B;IAIlD,MAAM,CAAC,eAAe;QACpB,OAAO,IAAI,+BAA+B,CAAC,GAAY,EAAE,CACvD,kCAAwB,CAAC,eAAe,EAAW,CACpD,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,WAAW,CAChB,UAAqD,EAAE;QAEvD,OAAO,IAAI,+BAA+B,CAAC,GAAY,EAAE,CACvD,kCAAwB,CAAC,cAAc,CAAU,OAAO,CAAC,CAC1D,CAAC;IACJ,CAAC;IAED,YACmB,uBAAiE;QAAjE,4BAAuB,GAAvB,uBAAuB,CAA0C;IACjF,CAAC;IAEG,eAAe,CACpB,mBAAiD;QAEjD,OAAO,IAAA,wBAAe,EACpB,+BAA+B,CAAC,0BAA0B,EAC1D,mBAAmB,CAAC,SAAS,EAC7B,GAAG,EAAE;YACH,MAAM,gBAAgB,GAAG,IAAI,CAAC,uBAAuB,EAAW,CAAC;YACjE,OAAO,IAAI,kCAAyB,CAClC,IAAI,kCAAwB,CAAC,mBAAmB,EAAE,gBAAgB,CAAC,CACpE,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC;;AAlCD,sEAAsE;AACvD,0DAA0B,GAAG,IAAI,GAAG,EAA0C,CAAC;kBAF3E,+BAA+B"}
@@ -6,20 +6,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const entity_1 = require("@expo/entity");
7
7
  const uuid_1 = require("uuid");
8
8
  const GenericLocalMemoryCacher_1 = __importDefault(require("../GenericLocalMemoryCacher"));
9
- const LocalMemoryCacheAdapter_1 = __importDefault(require("../LocalMemoryCacheAdapter"));
10
9
  const LocalMemoryCacheAdapterProvider_1 = __importDefault(require("../LocalMemoryCacheAdapterProvider"));
11
10
  const LocalMemoryTestEntity_1 = __importDefault(require("../testfixtures/LocalMemoryTestEntity"));
12
11
  const createLocalMemoryTestEntityCompanionProvider_1 = require("../testfixtures/createLocalMemoryTestEntityCompanionProvider");
13
- class TestViewerContext extends entity_1.ViewerContext {
14
- }
15
- describe(LocalMemoryCacheAdapter_1.default, () => {
12
+ describe(GenericLocalMemoryCacher_1.default, () => {
16
13
  beforeEach(async () => {
17
- LocalMemoryCacheAdapterProvider_1.default.localMemoryCacheAdapterMap.clear();
14
+ LocalMemoryCacheAdapterProvider_1.default['localMemoryCacheAdapterMap'].clear();
18
15
  });
19
16
  it('has correct caching behavior', async () => {
20
- const viewerContext = new TestViewerContext((0, createLocalMemoryTestEntityCompanionProvider_1.createLocalMemoryTestEntityCompanionProvider)());
21
- const cacheAdapter = viewerContext.entityCompanionProvider.getCompanionForEntity(LocalMemoryTestEntity_1.default, LocalMemoryTestEntity_1.default.getCompanionDefinition())['tableDataCoordinator']['cacheAdapter'];
22
- const cacheKeyMaker = cacheAdapter['makeCacheKey'].bind(cacheAdapter);
17
+ const viewerContext = new entity_1.ViewerContext((0, createLocalMemoryTestEntityCompanionProvider_1.createLocalMemoryTestEntityCompanionProvider)());
18
+ const genericCacher = viewerContext.entityCompanionProvider.getCompanionForEntity(LocalMemoryTestEntity_1.default)['tableDataCoordinator']['cacheAdapter']['genericCacher'];
19
+ const cacheKeyMaker = genericCacher['makeCacheKey'].bind(genericCacher);
23
20
  const date = new Date();
24
21
  const entity1Created = await LocalMemoryTestEntity_1.default.creator(viewerContext)
25
22
  .setField('name', 'blah')
@@ -29,7 +26,8 @@ describe(LocalMemoryCacheAdapter_1.default, () => {
29
26
  const entity1 = await LocalMemoryTestEntity_1.default.loader(viewerContext)
30
27
  .enforcing()
31
28
  .loadByIDAsync(entity1Created.getID());
32
- const entitySpecificGenericCacher = LocalMemoryCacheAdapterProvider_1.default.localMemoryCacheAdapterMap.get(LocalMemoryTestEntity_1.default.getCompanionDefinition().entityConfiguration.tableName)['genericLocalMemoryCacher'];
29
+ const entitySpecificGenericCacher = LocalMemoryCacheAdapterProvider_1.default['localMemoryCacheAdapterMap'].get(viewerContext.entityCompanionProvider.getCompanionForEntity(LocalMemoryTestEntity_1.default)
30
+ .entityCompanionDefinition.entityConfiguration.tableName)['genericCacher'];
33
31
  const cachedResult = await entitySpecificGenericCacher.loadManyAsync([
34
32
  cacheKeyMaker('id', entity1.getID()),
35
33
  ]);
@@ -65,7 +63,7 @@ describe(LocalMemoryCacheAdapter_1.default, () => {
65
63
  });
66
64
  it('shares the cache between different requests', async () => {
67
65
  const genericLocalMemoryCacherLoadManySpy = jest.spyOn(GenericLocalMemoryCacher_1.default.prototype, 'loadManyAsync');
68
- const viewerContext = new TestViewerContext((0, createLocalMemoryTestEntityCompanionProvider_1.createLocalMemoryTestEntityCompanionProvider)());
66
+ const viewerContext = new entity_1.ViewerContext((0, createLocalMemoryTestEntityCompanionProvider_1.createLocalMemoryTestEntityCompanionProvider)());
69
67
  const date = new Date();
70
68
  const entity1Created = await LocalMemoryTestEntity_1.default.creator(viewerContext)
71
69
  .setField('name', 'blah')
@@ -76,12 +74,12 @@ describe(LocalMemoryCacheAdapter_1.default, () => {
76
74
  .enforcing()
77
75
  .loadByIDAsync(entity1Created.getID());
78
76
  // load entity with a different request
79
- const viewerContext2 = new TestViewerContext((0, createLocalMemoryTestEntityCompanionProvider_1.createLocalMemoryTestEntityCompanionProvider)());
77
+ const viewerContext2 = new entity_1.ViewerContext((0, createLocalMemoryTestEntityCompanionProvider_1.createLocalMemoryTestEntityCompanionProvider)());
80
78
  const entity1WithVc2 = await LocalMemoryTestEntity_1.default.loader(viewerContext2)
81
79
  .enforcing()
82
80
  .loadByIDAsync(entity1Created.getID());
83
- const cacheAdapter = viewerContext.entityCompanionProvider.getCompanionForEntity(LocalMemoryTestEntity_1.default, LocalMemoryTestEntity_1.default.getCompanionDefinition())['tableDataCoordinator']['cacheAdapter'];
84
- const cacheKeyMaker = cacheAdapter['makeCacheKey'].bind(cacheAdapter);
81
+ const genericCacher = viewerContext.entityCompanionProvider.getCompanionForEntity(LocalMemoryTestEntity_1.default)['tableDataCoordinator']['cacheAdapter']['genericCacher'];
82
+ const cacheKeyMaker = genericCacher['makeCacheKey'].bind(genericCacher);
85
83
  expect(entity1WithVc2.getAllFields()).toMatchObject({
86
84
  id: entity1WithVc2.getID(),
87
85
  name: 'blah',
@@ -93,9 +91,9 @@ describe(LocalMemoryCacheAdapter_1.default, () => {
93
91
  expect(genericLocalMemoryCacherLoadManySpy).toBeCalledTimes(2);
94
92
  });
95
93
  it('respects the parameters of a noop cache', async () => {
96
- const viewerContext = new TestViewerContext((0, createLocalMemoryTestEntityCompanionProvider_1.createNoopLocalMemoryIntegrationTestEntityCompanionProvider)());
97
- const cacheAdapter = viewerContext.entityCompanionProvider.getCompanionForEntity(LocalMemoryTestEntity_1.default, LocalMemoryTestEntity_1.default.getCompanionDefinition())['tableDataCoordinator']['cacheAdapter'];
98
- const cacheKeyMaker = cacheAdapter['makeCacheKey'].bind(cacheAdapter);
94
+ const viewerContext = new entity_1.ViewerContext((0, createLocalMemoryTestEntityCompanionProvider_1.createNoopLocalMemoryIntegrationTestEntityCompanionProvider)());
95
+ const genericCacher = viewerContext.entityCompanionProvider.getCompanionForEntity(LocalMemoryTestEntity_1.default)['tableDataCoordinator']['cacheAdapter']['genericCacher'];
96
+ const cacheKeyMaker = genericCacher['makeCacheKey'].bind(genericCacher);
99
97
  const date = new Date();
100
98
  const entity1Created = await LocalMemoryTestEntity_1.default.creator(viewerContext)
101
99
  .setField('name', 'blah')
@@ -105,7 +103,8 @@ describe(LocalMemoryCacheAdapter_1.default, () => {
105
103
  const entity1 = await LocalMemoryTestEntity_1.default.loader(viewerContext)
106
104
  .enforcing()
107
105
  .loadByIDAsync(entity1Created.getID());
108
- const entitySpecificGenericCacher = LocalMemoryCacheAdapterProvider_1.default.localMemoryCacheAdapterMap.get(LocalMemoryTestEntity_1.default.getCompanionDefinition().entityConfiguration.tableName)['genericLocalMemoryCacher'];
106
+ const entitySpecificGenericCacher = LocalMemoryCacheAdapterProvider_1.default['localMemoryCacheAdapterMap'].get(viewerContext.entityCompanionProvider.getCompanionForEntity(LocalMemoryTestEntity_1.default)
107
+ .entityCompanionDefinition.entityConfiguration.tableName)['genericCacher'];
109
108
  const cachedResult = await entitySpecificGenericCacher.loadManyAsync([
110
109
  cacheKeyMaker('id', entity1.getID()),
111
110
  ]);
@@ -125,4 +124,4 @@ describe(LocalMemoryCacheAdapter_1.default, () => {
125
124
  });
126
125
  });
127
126
  });
128
- //# sourceMappingURL=LocalMemoryCacheAdapter-full-test.js.map
127
+ //# sourceMappingURL=GenericLocalMemoryCacher-full-test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GenericLocalMemoryCacher-full-test.js","sourceRoot":"","sources":["../../src/__tests__/GenericLocalMemoryCacher-full-test.ts"],"names":[],"mappings":";;;;;AAAA,yCAA0D;AAC1D,+BAAoC;AAEpC,2FAAmE;AACnE,yGAAiF;AACjF,kGAA0E;AAC1E,+HAGsE;AAEtE,QAAQ,CAAC,kCAAwB,EAAE,GAAG,EAAE;IACtC,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,yCAA+B,CAAC,4BAA4B,CAAC,CAAC,KAAK,EAAE,CAAC;IACxE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8BAA8B,EAAE,KAAK,IAAI,EAAE;QAC5C,MAAM,aAAa,GAAG,IAAI,sBAAa,CAAC,IAAA,2FAA4C,GAAE,CAAC,CAAC;QACxF,MAAM,aAAa,GACjB,aAAa,CAAC,uBAAuB,CAAC,qBAAqB,CAAC,+BAAqB,CAAC,CAChF,sBAAsB,CACvB,CAAC,cAAc,CAAC,CAAC,eAAe,CAAC,CAAC;QACrC,MAAM,aAAa,GAAG,aAAa,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAExE,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QACxB,MAAM,cAAc,GAAG,MAAM,+BAAqB,CAAC,OAAO,CAAC,aAAa,CAAC;aACtE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;aACxB,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC;aAC3B,kBAAkB,EAAE,CAAC;QAExB,2CAA2C;QAC3C,MAAM,OAAO,GAAG,MAAM,+BAAqB,CAAC,MAAM,CAAC,aAAa,CAAC;aAC9D,SAAS,EAAE;aACX,aAAa,CAAC,cAAc,CAAC,KAAK,EAAE,C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C,MAAM,uBAAuB,GAAG,MAAM,2BAA2B,CAAC,aAAa,CAAC;YAC9E,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC;SACnC,CAAC,CAAC;QACH,MAAM,CAAC,uBAAuB,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC;YACpF,MAAM,EAAE,oBAAW,CAAC,IAAI;SACzB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,9 +1,39 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
4
24
  };
5
25
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const GenericLocalMemoryCacher_1 = __importDefault(require("../GenericLocalMemoryCacher"));
26
+ const entity_1 = require("@expo/entity");
27
+ const GenericLocalMemoryCacher_1 = __importStar(require("../GenericLocalMemoryCacher"));
28
+ const entityConfiguration = new entity_1.EntityConfiguration({
29
+ idField: 'id',
30
+ tableName: 'blah',
31
+ schema: {
32
+ id: new entity_1.UUIDField({ columnName: 'id', cache: true }),
33
+ },
34
+ databaseAdapterFlavor: 'postgres',
35
+ cacheAdapterFlavor: 'local-memory',
36
+ });
7
37
  describe(GenericLocalMemoryCacher_1.default, () => {
8
38
  describe(GenericLocalMemoryCacher_1.default.createLRUCache, () => {
9
39
  it('creates a cache with default options', () => {
@@ -28,4 +58,69 @@ describe(GenericLocalMemoryCacher_1.default, () => {
28
58
  });
29
59
  });
30
60
  });
61
+ describe('Use within GenericEntityCacheAdapter', () => {
62
+ describe('loadManyAsync', () => {
63
+ it('returns appropriate cache results', async () => {
64
+ const cacheAdapter = new entity_1.GenericEntityCacheAdapter(new GenericLocalMemoryCacher_1.default(entityConfiguration, GenericLocalMemoryCacher_1.default.createLRUCache()));
65
+ const cacheHits = new Map([['test-id-1', { id: 'test-id-1' }]]);
66
+ await cacheAdapter.cacheManyAsync('id', cacheHits);
67
+ await cacheAdapter.cacheDBMissesAsync('id', ['test-id-2']);
68
+ const results = await cacheAdapter.loadManyAsync('id', [
69
+ 'test-id-1',
70
+ 'test-id-2',
71
+ 'test-id-3',
72
+ ]);
73
+ expect(results.get('test-id-1')).toMatchObject({
74
+ status: entity_1.CacheStatus.HIT,
75
+ item: { id: 'test-id-1' },
76
+ });
77
+ expect(results.get('test-id-2')).toMatchObject({ status: entity_1.CacheStatus.NEGATIVE });
78
+ expect(results.get('test-id-3')).toMatchObject({ status: entity_1.CacheStatus.MISS });
79
+ expect(results.size).toBe(3);
80
+ });
81
+ it('returns empty map when passed empty array of fieldValues', async () => {
82
+ const cacheAdapter = new entity_1.GenericEntityCacheAdapter(new GenericLocalMemoryCacher_1.default(entityConfiguration, GenericLocalMemoryCacher_1.default.createLRUCache()));
83
+ const results = await cacheAdapter.loadManyAsync('id', []);
84
+ expect(results).toEqual(new Map());
85
+ });
86
+ });
87
+ describe('cacheManyAsync', () => {
88
+ it('correctly caches all objects', async () => {
89
+ const localMemoryCache = GenericLocalMemoryCacher_1.default.createLRUCache({});
90
+ const localMemoryCacher = new GenericLocalMemoryCacher_1.default(entityConfiguration, localMemoryCache);
91
+ const cacheAdapter = new entity_1.GenericEntityCacheAdapter(localMemoryCacher);
92
+ await cacheAdapter.cacheManyAsync('id', new Map([['test-id-1', { id: 'test-id-1' }]]));
93
+ const cacheKey = localMemoryCacher['makeCacheKey']('id', 'test-id-1');
94
+ expect(localMemoryCache.get(cacheKey)).toMatchObject({
95
+ id: 'test-id-1',
96
+ });
97
+ });
98
+ });
99
+ describe('cacheDBMissesAsync', () => {
100
+ it('correctly caches misses', async () => {
101
+ const localMemoryCache = GenericLocalMemoryCacher_1.default.createLRUCache({});
102
+ const localMemoryCacher = new GenericLocalMemoryCacher_1.default(entityConfiguration, localMemoryCache);
103
+ const cacheAdapter = new entity_1.GenericEntityCacheAdapter(localMemoryCacher);
104
+ await cacheAdapter.cacheDBMissesAsync('id', ['test-id-1']);
105
+ const cacheKey = localMemoryCacher['makeCacheKey']('id', 'test-id-1');
106
+ expect(localMemoryCache.get(cacheKey)).toEqual(GenericLocalMemoryCacher_1.DOES_NOT_EXIST_LOCAL_MEMORY_CACHE);
107
+ });
108
+ });
109
+ describe('invalidateManyAsync', () => {
110
+ it('invalidates correctly', async () => {
111
+ const localMemoryCache = GenericLocalMemoryCacher_1.default.createLRUCache({});
112
+ const cacheAdapter = new entity_1.GenericEntityCacheAdapter(new GenericLocalMemoryCacher_1.default(entityConfiguration, localMemoryCache));
113
+ await cacheAdapter.cacheManyAsync('id', new Map([['test-id-1', { id: 'test-id-1' }]]));
114
+ await cacheAdapter.cacheDBMissesAsync('id', ['test-id-2']);
115
+ await cacheAdapter.invalidateManyAsync('id', ['test-id-1', 'test-id-2']);
116
+ const results = await cacheAdapter.loadManyAsync('id', ['test-id-1', 'test-id-2']);
117
+ expect(results.get('test-id-1')).toMatchObject({ status: entity_1.CacheStatus.MISS });
118
+ expect(results.get('test-id-2')).toMatchObject({ status: entity_1.CacheStatus.MISS });
119
+ });
120
+ it('returns when passed empty array of fieldValues', async () => {
121
+ const cacheAdapter = new entity_1.GenericEntityCacheAdapter(new GenericLocalMemoryCacher_1.default(entityConfiguration, GenericLocalMemoryCacher_1.default.createLRUCache({})));
122
+ await cacheAdapter.invalidateManyAsync('id', []);
123
+ });
124
+ });
125
+ });
31
126
  //# sourceMappingURL=GenericLocalMemoryCacher-test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"GenericLocalMemoryCacher-test.js","sourceRoot":"","sources":["../../src/__tests__/GenericLocalMemoryCacher-test.ts"],"names":[],"mappings":";;;;;AAAA,2FAAmE;AAEnE,QAAQ,CAAC,kCAAwB,EAAE,GAAG,EAAE;IACtC,QAAQ,CAAC,kCAAwB,CAAC,cAAc,EAAE,GAAG,EAAE;QACrD,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;YAC9C,MAAM,KAAK,GAAG,kCAAwB,CAAC,cAAc,EAAE,CAAC;YACxD,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC9B,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,4BAA4B,EAAE,GAAG,EAAE;YACpC,MAAM,KAAK,GAAG,kCAAwB,CAAC,cAAc,CAAC;gBACpD,UAAU,EAAE,CAAC;gBACb,OAAO,EAAE,EAAE;aACZ,CAAC,CAAC;YACH,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC3B,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,kCAAwB,CAAC,eAAe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AI,EAAE,EAAE,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/build/index.d.ts CHANGED
@@ -4,5 +4,4 @@
4
4
  */
5
5
  export { default as GenericLocalMemoryCacher } from './GenericLocalMemoryCacher';
6
6
  export * from './GenericLocalMemoryCacher';
7
- export { default as LocalMemoryCacheAdapter } from './LocalMemoryCacheAdapter';
8
7
  export { default as LocalMemoryCacheAdapterProvider } from './LocalMemoryCacheAdapterProvider';
package/build/index.js CHANGED
@@ -22,12 +22,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.LocalMemoryCacheAdapterProvider = exports.LocalMemoryCacheAdapter = exports.GenericLocalMemoryCacher = void 0;
25
+ exports.LocalMemoryCacheAdapterProvider = exports.GenericLocalMemoryCacher = void 0;
26
26
  var GenericLocalMemoryCacher_1 = require("./GenericLocalMemoryCacher");
27
27
  Object.defineProperty(exports, "GenericLocalMemoryCacher", { enumerable: true, get: function () { return __importDefault(GenericLocalMemoryCacher_1).default; } });
28
28
  __exportStar(require("./GenericLocalMemoryCacher"), exports);
29
- var LocalMemoryCacheAdapter_1 = require("./LocalMemoryCacheAdapter");
30
- Object.defineProperty(exports, "LocalMemoryCacheAdapter", { enumerable: true, get: function () { return __importDefault(LocalMemoryCacheAdapter_1).default; } });
31
29
  var LocalMemoryCacheAdapterProvider_1 = require("./LocalMemoryCacheAdapterProvider");
32
30
  Object.defineProperty(exports, "LocalMemoryCacheAdapterProvider", { enumerable: true, get: function () { return __importDefault(LocalMemoryCacheAdapterProvider_1).default; } });
33
31
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,iCAAiC;AACjC;;;GAGG;;;;;;;;;;;;;;;;;;;;AAEH,uEAAiF;AAAxE,qJAAA,OAAO,OAA4B;AAC5C,6DAA2C;AAC3C,qEAA+E;AAAtE,mJAAA,OAAO,OAA2B;AAC3C,qFAA+F;AAAtF,mKAAA,OAAO,OAAmC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,iCAAiC;AACjC;;;GAGG;;;;;;;;;;;;;;;;;;;;AAEH,uEAAiF;AAAxE,qJAAA,OAAO,OAA4B;AAC5C,6DAA2C;AAC3C,qFAA+F;AAAtF,mKAAA,OAAO,OAAmC"}
@@ -1,11 +1,11 @@
1
1
  import { AlwaysAllowPrivacyPolicyRule, EntityPrivacyPolicy, ViewerContext, EntityConfiguration, EntityCompanionDefinition, Entity } from '@expo/entity';
2
- export declare type LocalMemoryTestEntityFields = {
2
+ export type LocalMemoryTestEntityFields = {
3
3
  id: string;
4
4
  name: string;
5
5
  dateField: Date | null;
6
6
  };
7
7
  export default class LocalMemoryTestEntity extends Entity<LocalMemoryTestEntityFields, string, ViewerContext> {
8
- static getCompanionDefinition(): EntityCompanionDefinition<LocalMemoryTestEntityFields, string, ViewerContext, LocalMemoryTestEntity, LocalMemoryTestEntityPrivacyPolicy>;
8
+ static defineCompanionDefinition(): EntityCompanionDefinition<LocalMemoryTestEntityFields, string, ViewerContext, LocalMemoryTestEntity, LocalMemoryTestEntityPrivacyPolicy>;
9
9
  }
10
10
  export declare class LocalMemoryTestEntityPrivacyPolicy extends EntityPrivacyPolicy<LocalMemoryTestEntityFields, string, ViewerContext, LocalMemoryTestEntity> {
11
11
  protected readonly createRules: AlwaysAllowPrivacyPolicyRule<LocalMemoryTestEntityFields, string, ViewerContext, LocalMemoryTestEntity, keyof LocalMemoryTestEntityFields>[];
@@ -3,8 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.localMemoryTestEntityConfiguration = exports.LocalMemoryTestEntityPrivacyPolicy = void 0;
4
4
  const entity_1 = require("@expo/entity");
5
5
  class LocalMemoryTestEntity extends entity_1.Entity {
6
- static getCompanionDefinition() {
7
- return localMemoryTestEntityCompanionDefinition;
6
+ static defineCompanionDefinition() {
7
+ return {
8
+ entityClass: LocalMemoryTestEntity,
9
+ entityConfiguration: exports.localMemoryTestEntityConfiguration,
10
+ privacyPolicyClass: LocalMemoryTestEntityPrivacyPolicy,
11
+ };
8
12
  }
9
13
  }
10
14
  exports.default = LocalMemoryTestEntity;
@@ -45,9 +49,4 @@ exports.localMemoryTestEntityConfiguration = new entity_1.EntityConfiguration({
45
49
  databaseAdapterFlavor: 'postgres',
46
50
  cacheAdapterFlavor: 'local-memory',
47
51
  });
48
- const localMemoryTestEntityCompanionDefinition = new entity_1.EntityCompanionDefinition({
49
- entityClass: LocalMemoryTestEntity,
50
- entityConfiguration: exports.localMemoryTestEntityConfiguration,
51
- privacyPolicyClass: LocalMemoryTestEntityPrivacyPolicy,
52
- });
53
52
  //# sourceMappingURL=LocalMemoryTestEntity.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"LocalMemoryTestEntity.js","sourceRoot":"","sources":["../../src/testfixtures/LocalMemoryTestEntity.ts"],"names":[],"mappings":";;;AAAA,yCAUsB;AAQtB,MAAqB,qBAAsB,SAAQ,eAIlD;IACC,MAAM,CAAC,sBAAsB;QAO3B,OAAO,wCAAwC,CAAC;IAClD,CAAC;CACF;AAdD,wCAcC;AAED,MAAa,kCAAmC,SAAQ,4BAKvD;IALD;;QAM8B,gBAAW,GAAG;YACxC,IAAI,qCAA4B,EAK7B;SACJ,CAAC;QAC0B,cAAS,GAAG;YACtC,IAAI,qCAA4B,EAK7B;SACJ,CAAC;QAC0B,gBAAW,GAAG;YACxC,IAAI,qCAA4B,EAK7B;SACJ,CAAC;QAC0B,gBAAW,GAAG;YACxC,IAAI,qCAA4B,EAK7B;SACJ,CAAC;IACJ,CAAC;CAAA;AAtCD,gFAsCC;AAEY,QAAA,kCAAkC,GAC7C,IAAI,4BAAmB,CAA8B;IACnD,OAAO,EAAE,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,EAAE,IAAI;IACb,SAAS,EAAE,4BAA4B;IACvC,MAAM,EAAE;QACN,EAAE,EAAE,IAAI,kBAAS,CAAC;YAChB,UAAU,EAAE,IAAI;YAChB,KAAK,EAAE,IAAI;SACZ,CAAC;QACF,IAAI,EAAE,IAAI,oBAAW,CAAC;YACpB,UAAU,EAAE,MAAM;YAClB,KAAK,EAAE,IAAI;SACZ,CAAC;QACF,SAAS,EAAE,IAAI,kBAAS,CAAC;YACvB,UAAU,EAAE,YAAY;SACzB,CAAC;KACH;IACD,qBAAqB,EAAE,UAAU;IACjC,kBAAkB,EAAE,cAAc;CACnC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expo/entity-cache-adapter-local-memory",
3
- "version": "0.31.0",
3
+ "version": "0.32.0",
4
4
  "description": "Cross-request local memory cache adapter for @expo/entity",
5
5
  "files": [
6
6
  "build",
@@ -19,7 +19,7 @@
19
19
  "barrelsby": "barrelsby --directory src --location top --exclude tests__ --singleQuotes --exportDefault --delete"
20
20
  },
21
21
  "engines": {
22
- "node": ">=12"
22
+ "node": ">=16"
23
23
  },
24
24
  "keywords": [
25
25
  "entity"
@@ -33,7 +33,7 @@
33
33
  "lru-cache": "^6.0.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@expo/entity": "^0.31.0"
36
+ "@expo/entity": "^0.32.0"
37
37
  },
38
- "gitHead": "92f5529ebad6dbec6887538e1d1900968ffc9738"
38
+ "gitHead": "d2a4405fa1af673a98e36b9b7c76c0ee7961a23e"
39
39
  }
@@ -1,4 +1,10 @@
1
- import { CacheLoadResult, CacheStatus, IEntityGenericCacher } from '@expo/entity';
1
+ import {
2
+ CacheLoadResult,
3
+ CacheStatus,
4
+ EntityConfiguration,
5
+ IEntityGenericCacher,
6
+ } from '@expo/entity';
7
+ import invariant from 'invariant';
2
8
  import LRUCache from 'lru-cache';
3
9
 
4
10
  // Sentinel value we store in local memory to negatively cache a database miss.
@@ -8,7 +14,10 @@ type LocalMemoryCacheValue<TFields> = Readonly<TFields> | typeof DOES_NOT_EXIST_
8
14
  export type LocalMemoryCache<TFields> = LRUCache<string, LocalMemoryCacheValue<TFields>>;
9
15
 
10
16
  export default class GenericLocalMemoryCacher<TFields> implements IEntityGenericCacher<TFields> {
11
- constructor(private readonly localMemoryCache: LocalMemoryCache<TFields>) {}
17
+ constructor(
18
+ private readonly entityConfiguration: EntityConfiguration<TFields>,
19
+ private readonly localMemoryCache: LocalMemoryCache<TFields>
20
+ ) {}
12
21
 
13
22
  static createLRUCache<TFields>(
14
23
  options: { maxSize?: number; ttlSeconds?: number } = {}
@@ -72,7 +81,19 @@ export default class GenericLocalMemoryCacher<TFields> implements IEntityGeneric
72
81
  }
73
82
  }
74
83
 
75
- public makeCacheKey(parts: string[]): string {
84
+ public makeCacheKey<N extends keyof TFields>(
85
+ fieldName: N,
86
+ fieldValue: NonNullable<TFields[N]>
87
+ ): string {
88
+ const columnName = this.entityConfiguration.entityToDBFieldsKeyMapping.get(fieldName);
89
+ invariant(columnName, `database field mapping missing for ${String(fieldName)}`);
90
+ const parts = [
91
+ this.entityConfiguration.tableName,
92
+ `${this.entityConfiguration.cacheKeyVersion}`,
93
+ columnName,
94
+ String(fieldValue),
95
+ ];
96
+
76
97
  const delimiter = ':';
77
98
  const escapedParts = parts.map((part) =>
78
99
  part.replace('\\', '\\\\').replace(delimiter, `\\${delimiter}`)
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  computeIfAbsent,
3
- EntityCacheAdapter,
3
+ IEntityCacheAdapter,
4
4
  EntityConfiguration,
5
+ GenericEntityCacheAdapter,
5
6
  IEntityCacheAdapterProvider,
6
7
  } from '@expo/entity';
7
8
 
8
9
  import GenericLocalMemoryCacher, { LocalMemoryCache } from './GenericLocalMemoryCacher';
9
- import LocalMemoryCacheAdapter from './LocalMemoryCacheAdapter';
10
10
 
11
11
  export default class LocalMemoryCacheAdapterProvider implements IEntityCacheAdapterProvider {
12
12
  // local memory cache adapters should be shared/reused across requests
13
- static localMemoryCacheAdapterMap = new Map<string, LocalMemoryCacheAdapter<any>>();
13
+ private static localMemoryCacheAdapterMap = new Map<string, GenericEntityCacheAdapter<any>>();
14
14
 
15
15
  static getNoOpProvider(): IEntityCacheAdapterProvider {
16
16
  return new LocalMemoryCacheAdapterProvider(<TFields>() =>
@@ -32,13 +32,15 @@ export default class LocalMemoryCacheAdapterProvider implements IEntityCacheAdap
32
32
 
33
33
  public getCacheAdapter<TFields>(
34
34
  entityConfiguration: EntityConfiguration<TFields>
35
- ): EntityCacheAdapter<TFields> {
35
+ ): IEntityCacheAdapter<TFields> {
36
36
  return computeIfAbsent(
37
37
  LocalMemoryCacheAdapterProvider.localMemoryCacheAdapterMap,
38
38
  entityConfiguration.tableName,
39
39
  () => {
40
40
  const localMemoryCache = this.localMemoryCacheCreator<TFields>();
41
- return new LocalMemoryCacheAdapter(entityConfiguration, localMemoryCache);
41
+ return new GenericEntityCacheAdapter(
42
+ new GenericLocalMemoryCacher(entityConfiguration, localMemoryCache)
43
+ );
42
44
  }
43
45
  );
44
46
  }