@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.
- package/build/GenericLocalMemoryCacher.d.ts +6 -5
- package/build/GenericLocalMemoryCacher.js +14 -5
- package/build/GenericLocalMemoryCacher.js.map +1 -1
- package/build/LocalMemoryCacheAdapterProvider.d.ts +3 -4
- package/build/LocalMemoryCacheAdapterProvider.js +5 -6
- package/build/LocalMemoryCacheAdapterProvider.js.map +1 -1
- package/build/__tests__/{LocalMemoryCacheAdapter-full-test.js → GenericLocalMemoryCacher-full-test.js} +17 -18
- package/build/__tests__/GenericLocalMemoryCacher-full-test.js.map +1 -0
- package/build/__tests__/GenericLocalMemoryCacher-test.js +98 -3
- package/build/__tests__/GenericLocalMemoryCacher-test.js.map +1 -1
- package/build/index.d.ts +0 -1
- package/build/index.js +1 -3
- package/build/index.js.map +1 -1
- package/build/testfixtures/LocalMemoryTestEntity.d.ts +2 -2
- package/build/testfixtures/LocalMemoryTestEntity.js +6 -7
- package/build/testfixtures/LocalMemoryTestEntity.js.map +1 -1
- package/package.json +4 -4
- package/src/GenericLocalMemoryCacher.ts +24 -3
- package/src/LocalMemoryCacheAdapterProvider.ts +7 -5
- package/src/__tests__/{LocalMemoryCacheAdapter-full-test.ts → GenericLocalMemoryCacher-full-test.ts} +33 -32
- package/src/__tests__/GenericLocalMemoryCacher-test.ts +115 -1
- package/src/index.ts +0 -1
- package/src/testfixtures/LocalMemoryTestEntity.ts +6 -8
- package/build/LocalMemoryCacheAdapter.d.ts +0 -11
- package/build/LocalMemoryCacheAdapter.js +0 -45
- package/build/LocalMemoryCacheAdapter.js.map +0 -1
- package/build/__tests__/LocalMemoryCacheAdapter-full-test.js.map +0 -1
- package/build/__tests__/LocalMemoryCacheAdapter-test.d.ts +0 -1
- package/build/__tests__/LocalMemoryCacheAdapter-test.js +0 -104
- package/build/__tests__/LocalMemoryCacheAdapter-test.js.map +0 -1
- package/src/LocalMemoryCacheAdapter.ts +0 -80
- package/src/__tests__/LocalMemoryCacheAdapter-test.ts +0 -107
- /package/build/__tests__/{LocalMemoryCacheAdapter-full-test.d.ts → GenericLocalMemoryCacher-full-test.d.ts} +0 -0
package/src/__tests__/{LocalMemoryCacheAdapter-full-test.ts → GenericLocalMemoryCacher-full-test.ts}
RENAMED
|
@@ -2,7 +2,6 @@ import { CacheStatus, ViewerContext } from '@expo/entity';
|
|
|
2
2
|
import { v4 as uuidv4 } from 'uuid';
|
|
3
3
|
|
|
4
4
|
import GenericLocalMemoryCacher from '../GenericLocalMemoryCacher';
|
|
5
|
-
import LocalMemoryCacheAdapter from '../LocalMemoryCacheAdapter';
|
|
6
5
|
import LocalMemoryCacheAdapterProvider from '../LocalMemoryCacheAdapterProvider';
|
|
7
6
|
import LocalMemoryTestEntity from '../testfixtures/LocalMemoryTestEntity';
|
|
8
7
|
import {
|
|
@@ -10,20 +9,18 @@ import {
|
|
|
10
9
|
createNoopLocalMemoryIntegrationTestEntityCompanionProvider,
|
|
11
10
|
} from '../testfixtures/createLocalMemoryTestEntityCompanionProvider';
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
describe(LocalMemoryCacheAdapter, () => {
|
|
12
|
+
describe(GenericLocalMemoryCacher, () => {
|
|
16
13
|
beforeEach(async () => {
|
|
17
|
-
LocalMemoryCacheAdapterProvider
|
|
14
|
+
LocalMemoryCacheAdapterProvider['localMemoryCacheAdapterMap'].clear();
|
|
18
15
|
});
|
|
19
16
|
|
|
20
17
|
it('has correct caching behavior', async () => {
|
|
21
|
-
const viewerContext = new
|
|
22
|
-
const
|
|
23
|
-
LocalMemoryTestEntity
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const cacheKeyMaker =
|
|
18
|
+
const viewerContext = new ViewerContext(createLocalMemoryTestEntityCompanionProvider());
|
|
19
|
+
const genericCacher =
|
|
20
|
+
viewerContext.entityCompanionProvider.getCompanionForEntity(LocalMemoryTestEntity)[
|
|
21
|
+
'tableDataCoordinator'
|
|
22
|
+
]['cacheAdapter']['genericCacher'];
|
|
23
|
+
const cacheKeyMaker = genericCacher['makeCacheKey'].bind(genericCacher);
|
|
27
24
|
|
|
28
25
|
const date = new Date();
|
|
29
26
|
const entity1Created = await LocalMemoryTestEntity.creator(viewerContext)
|
|
@@ -36,10 +33,12 @@ describe(LocalMemoryCacheAdapter, () => {
|
|
|
36
33
|
.enforcing()
|
|
37
34
|
.loadByIDAsync(entity1Created.getID());
|
|
38
35
|
|
|
39
|
-
const entitySpecificGenericCacher =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
)
|
|
36
|
+
const entitySpecificGenericCacher = LocalMemoryCacheAdapterProvider[
|
|
37
|
+
'localMemoryCacheAdapterMap'
|
|
38
|
+
].get(
|
|
39
|
+
viewerContext.entityCompanionProvider.getCompanionForEntity(LocalMemoryTestEntity)
|
|
40
|
+
.entityCompanionDefinition.entityConfiguration.tableName
|
|
41
|
+
)!['genericCacher'];
|
|
43
42
|
const cachedResult = await entitySpecificGenericCacher.loadManyAsync([
|
|
44
43
|
cacheKeyMaker('id', entity1.getID()),
|
|
45
44
|
]);
|
|
@@ -88,7 +87,7 @@ describe(LocalMemoryCacheAdapter, () => {
|
|
|
88
87
|
GenericLocalMemoryCacher.prototype as unknown as any,
|
|
89
88
|
'loadManyAsync'
|
|
90
89
|
);
|
|
91
|
-
const viewerContext = new
|
|
90
|
+
const viewerContext = new ViewerContext(createLocalMemoryTestEntityCompanionProvider());
|
|
92
91
|
|
|
93
92
|
const date = new Date();
|
|
94
93
|
const entity1Created = await LocalMemoryTestEntity.creator(viewerContext)
|
|
@@ -102,16 +101,16 @@ describe(LocalMemoryCacheAdapter, () => {
|
|
|
102
101
|
.loadByIDAsync(entity1Created.getID());
|
|
103
102
|
|
|
104
103
|
// load entity with a different request
|
|
105
|
-
const viewerContext2 = new
|
|
104
|
+
const viewerContext2 = new ViewerContext(createLocalMemoryTestEntityCompanionProvider());
|
|
106
105
|
const entity1WithVc2 = await LocalMemoryTestEntity.loader(viewerContext2)
|
|
107
106
|
.enforcing()
|
|
108
107
|
.loadByIDAsync(entity1Created.getID());
|
|
109
108
|
|
|
110
|
-
const
|
|
111
|
-
LocalMemoryTestEntity
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const cacheKeyMaker =
|
|
109
|
+
const genericCacher =
|
|
110
|
+
viewerContext.entityCompanionProvider.getCompanionForEntity(LocalMemoryTestEntity)[
|
|
111
|
+
'tableDataCoordinator'
|
|
112
|
+
]['cacheAdapter']['genericCacher'];
|
|
113
|
+
const cacheKeyMaker = genericCacher['makeCacheKey'].bind(genericCacher);
|
|
115
114
|
expect(entity1WithVc2.getAllFields()).toMatchObject({
|
|
116
115
|
id: entity1WithVc2.getID(),
|
|
117
116
|
name: 'blah',
|
|
@@ -124,14 +123,14 @@ describe(LocalMemoryCacheAdapter, () => {
|
|
|
124
123
|
});
|
|
125
124
|
|
|
126
125
|
it('respects the parameters of a noop cache', async () => {
|
|
127
|
-
const viewerContext = new
|
|
126
|
+
const viewerContext = new ViewerContext(
|
|
128
127
|
createNoopLocalMemoryIntegrationTestEntityCompanionProvider()
|
|
129
128
|
);
|
|
130
|
-
const
|
|
131
|
-
LocalMemoryTestEntity
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const cacheKeyMaker =
|
|
129
|
+
const genericCacher =
|
|
130
|
+
viewerContext.entityCompanionProvider.getCompanionForEntity(LocalMemoryTestEntity)[
|
|
131
|
+
'tableDataCoordinator'
|
|
132
|
+
]['cacheAdapter']['genericCacher'];
|
|
133
|
+
const cacheKeyMaker = genericCacher['makeCacheKey'].bind(genericCacher);
|
|
135
134
|
|
|
136
135
|
const date = new Date();
|
|
137
136
|
const entity1Created = await LocalMemoryTestEntity.creator(viewerContext)
|
|
@@ -144,10 +143,12 @@ describe(LocalMemoryCacheAdapter, () => {
|
|
|
144
143
|
.enforcing()
|
|
145
144
|
.loadByIDAsync(entity1Created.getID());
|
|
146
145
|
|
|
147
|
-
const entitySpecificGenericCacher =
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
)
|
|
146
|
+
const entitySpecificGenericCacher = LocalMemoryCacheAdapterProvider[
|
|
147
|
+
'localMemoryCacheAdapterMap'
|
|
148
|
+
].get(
|
|
149
|
+
viewerContext.entityCompanionProvider.getCompanionForEntity(LocalMemoryTestEntity)
|
|
150
|
+
.entityCompanionDefinition.entityConfiguration.tableName
|
|
151
|
+
)!['genericCacher'];
|
|
151
152
|
const cachedResult = await entitySpecificGenericCacher.loadManyAsync([
|
|
152
153
|
cacheKeyMaker('id', entity1.getID()),
|
|
153
154
|
]);
|
|
@@ -1,4 +1,27 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
CacheStatus,
|
|
3
|
+
UUIDField,
|
|
4
|
+
EntityConfiguration,
|
|
5
|
+
GenericEntityCacheAdapter,
|
|
6
|
+
} from '@expo/entity';
|
|
7
|
+
|
|
8
|
+
import GenericLocalMemoryCacher, {
|
|
9
|
+
DOES_NOT_EXIST_LOCAL_MEMORY_CACHE,
|
|
10
|
+
} from '../GenericLocalMemoryCacher';
|
|
11
|
+
|
|
12
|
+
type BlahFields = {
|
|
13
|
+
id: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const entityConfiguration = new EntityConfiguration<BlahFields>({
|
|
17
|
+
idField: 'id',
|
|
18
|
+
tableName: 'blah',
|
|
19
|
+
schema: {
|
|
20
|
+
id: new UUIDField({ columnName: 'id', cache: true }),
|
|
21
|
+
},
|
|
22
|
+
databaseAdapterFlavor: 'postgres',
|
|
23
|
+
cacheAdapterFlavor: 'local-memory',
|
|
24
|
+
});
|
|
2
25
|
|
|
3
26
|
describe(GenericLocalMemoryCacher, () => {
|
|
4
27
|
describe(GenericLocalMemoryCacher.createLRUCache, () => {
|
|
@@ -26,3 +49,94 @@ describe(GenericLocalMemoryCacher, () => {
|
|
|
26
49
|
});
|
|
27
50
|
});
|
|
28
51
|
});
|
|
52
|
+
|
|
53
|
+
describe('Use within GenericEntityCacheAdapter', () => {
|
|
54
|
+
describe('loadManyAsync', () => {
|
|
55
|
+
it('returns appropriate cache results', async () => {
|
|
56
|
+
const cacheAdapter = new GenericEntityCacheAdapter(
|
|
57
|
+
new GenericLocalMemoryCacher(entityConfiguration, GenericLocalMemoryCacher.createLRUCache())
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const cacheHits = new Map<string, Readonly<BlahFields>>([['test-id-1', { id: 'test-id-1' }]]);
|
|
61
|
+
await cacheAdapter.cacheManyAsync('id', cacheHits);
|
|
62
|
+
await cacheAdapter.cacheDBMissesAsync('id', ['test-id-2']);
|
|
63
|
+
|
|
64
|
+
const results = await cacheAdapter.loadManyAsync('id', [
|
|
65
|
+
'test-id-1',
|
|
66
|
+
'test-id-2',
|
|
67
|
+
'test-id-3',
|
|
68
|
+
]);
|
|
69
|
+
|
|
70
|
+
expect(results.get('test-id-1')).toMatchObject({
|
|
71
|
+
status: CacheStatus.HIT,
|
|
72
|
+
item: { id: 'test-id-1' },
|
|
73
|
+
});
|
|
74
|
+
expect(results.get('test-id-2')).toMatchObject({ status: CacheStatus.NEGATIVE });
|
|
75
|
+
expect(results.get('test-id-3')).toMatchObject({ status: CacheStatus.MISS });
|
|
76
|
+
expect(results.size).toBe(3);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('returns empty map when passed empty array of fieldValues', async () => {
|
|
80
|
+
const cacheAdapter = new GenericEntityCacheAdapter(
|
|
81
|
+
new GenericLocalMemoryCacher(entityConfiguration, GenericLocalMemoryCacher.createLRUCache())
|
|
82
|
+
);
|
|
83
|
+
const results = await cacheAdapter.loadManyAsync('id', []);
|
|
84
|
+
expect(results).toEqual(new Map());
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('cacheManyAsync', () => {
|
|
89
|
+
it('correctly caches all objects', async () => {
|
|
90
|
+
const localMemoryCache = GenericLocalMemoryCacher.createLRUCache<BlahFields>({});
|
|
91
|
+
|
|
92
|
+
const localMemoryCacher = new GenericLocalMemoryCacher(entityConfiguration, localMemoryCache);
|
|
93
|
+
const cacheAdapter = new GenericEntityCacheAdapter(localMemoryCacher);
|
|
94
|
+
await cacheAdapter.cacheManyAsync('id', new Map([['test-id-1', { id: 'test-id-1' }]]));
|
|
95
|
+
|
|
96
|
+
const cacheKey = localMemoryCacher['makeCacheKey']('id', 'test-id-1');
|
|
97
|
+
expect(localMemoryCache.get(cacheKey)).toMatchObject({
|
|
98
|
+
id: 'test-id-1',
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('cacheDBMissesAsync', () => {
|
|
104
|
+
it('correctly caches misses', async () => {
|
|
105
|
+
const localMemoryCache = GenericLocalMemoryCacher.createLRUCache<BlahFields>({});
|
|
106
|
+
|
|
107
|
+
const localMemoryCacher = new GenericLocalMemoryCacher(entityConfiguration, localMemoryCache);
|
|
108
|
+
const cacheAdapter = new GenericEntityCacheAdapter(localMemoryCacher);
|
|
109
|
+
await cacheAdapter.cacheDBMissesAsync('id', ['test-id-1']);
|
|
110
|
+
|
|
111
|
+
const cacheKey = localMemoryCacher['makeCacheKey']('id', 'test-id-1');
|
|
112
|
+
expect(localMemoryCache.get(cacheKey)).toEqual(DOES_NOT_EXIST_LOCAL_MEMORY_CACHE);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
describe('invalidateManyAsync', () => {
|
|
117
|
+
it('invalidates correctly', async () => {
|
|
118
|
+
const localMemoryCache = GenericLocalMemoryCacher.createLRUCache<BlahFields>({});
|
|
119
|
+
|
|
120
|
+
const cacheAdapter = new GenericEntityCacheAdapter(
|
|
121
|
+
new GenericLocalMemoryCacher(entityConfiguration, localMemoryCache)
|
|
122
|
+
);
|
|
123
|
+
await cacheAdapter.cacheManyAsync('id', new Map([['test-id-1', { id: 'test-id-1' }]]));
|
|
124
|
+
await cacheAdapter.cacheDBMissesAsync('id', ['test-id-2']);
|
|
125
|
+
await cacheAdapter.invalidateManyAsync('id', ['test-id-1', 'test-id-2']);
|
|
126
|
+
|
|
127
|
+
const results = await cacheAdapter.loadManyAsync('id', ['test-id-1', 'test-id-2']);
|
|
128
|
+
expect(results.get('test-id-1')).toMatchObject({ status: CacheStatus.MISS });
|
|
129
|
+
expect(results.get('test-id-2')).toMatchObject({ status: CacheStatus.MISS });
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('returns when passed empty array of fieldValues', async () => {
|
|
133
|
+
const cacheAdapter = new GenericEntityCacheAdapter(
|
|
134
|
+
new GenericLocalMemoryCacher(
|
|
135
|
+
entityConfiguration,
|
|
136
|
+
GenericLocalMemoryCacher.createLRUCache<BlahFields>({})
|
|
137
|
+
)
|
|
138
|
+
);
|
|
139
|
+
await cacheAdapter.invalidateManyAsync('id', []);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -6,5 +6,4 @@
|
|
|
6
6
|
|
|
7
7
|
export { default as GenericLocalMemoryCacher } from './GenericLocalMemoryCacher';
|
|
8
8
|
export * from './GenericLocalMemoryCacher';
|
|
9
|
-
export { default as LocalMemoryCacheAdapter } from './LocalMemoryCacheAdapter';
|
|
10
9
|
export { default as LocalMemoryCacheAdapterProvider } from './LocalMemoryCacheAdapterProvider';
|
|
@@ -21,14 +21,18 @@ export default class LocalMemoryTestEntity extends Entity<
|
|
|
21
21
|
string,
|
|
22
22
|
ViewerContext
|
|
23
23
|
> {
|
|
24
|
-
static
|
|
24
|
+
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
25
25
|
LocalMemoryTestEntityFields,
|
|
26
26
|
string,
|
|
27
27
|
ViewerContext,
|
|
28
28
|
LocalMemoryTestEntity,
|
|
29
29
|
LocalMemoryTestEntityPrivacyPolicy
|
|
30
30
|
> {
|
|
31
|
-
return
|
|
31
|
+
return {
|
|
32
|
+
entityClass: LocalMemoryTestEntity,
|
|
33
|
+
entityConfiguration: localMemoryTestEntityConfiguration,
|
|
34
|
+
privacyPolicyClass: LocalMemoryTestEntityPrivacyPolicy,
|
|
35
|
+
};
|
|
32
36
|
}
|
|
33
37
|
}
|
|
34
38
|
|
|
@@ -92,9 +96,3 @@ export const localMemoryTestEntityConfiguration =
|
|
|
92
96
|
databaseAdapterFlavor: 'postgres',
|
|
93
97
|
cacheAdapterFlavor: 'local-memory',
|
|
94
98
|
});
|
|
95
|
-
|
|
96
|
-
const localMemoryTestEntityCompanionDefinition = new EntityCompanionDefinition({
|
|
97
|
-
entityClass: LocalMemoryTestEntity,
|
|
98
|
-
entityConfiguration: localMemoryTestEntityConfiguration,
|
|
99
|
-
privacyPolicyClass: LocalMemoryTestEntityPrivacyPolicy,
|
|
100
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { EntityCacheAdapter, CacheLoadResult, EntityConfiguration } from '@expo/entity';
|
|
2
|
-
import { LocalMemoryCache } from './GenericLocalMemoryCacher';
|
|
3
|
-
export default class LocalMemoryCacheAdapter<TFields> extends EntityCacheAdapter<TFields> {
|
|
4
|
-
private readonly genericLocalMemoryCacher;
|
|
5
|
-
constructor(entityConfiguration: EntityConfiguration<TFields>, localMemoryCache: LocalMemoryCache<TFields>);
|
|
6
|
-
loadManyAsync<N extends keyof TFields>(fieldName: N, fieldValues: readonly NonNullable<TFields[N]>[]): Promise<ReadonlyMap<NonNullable<TFields[N]>, CacheLoadResult<TFields>>>;
|
|
7
|
-
cacheManyAsync<N extends keyof TFields>(fieldName: N, objectMap: ReadonlyMap<NonNullable<TFields[N]>, Readonly<TFields>>): Promise<void>;
|
|
8
|
-
cacheDBMissesAsync<N extends keyof TFields>(fieldName: N, fieldValues: readonly NonNullable<TFields[N]>[]): Promise<void>;
|
|
9
|
-
invalidateManyAsync<N extends keyof TFields>(fieldName: N, fieldValues: readonly NonNullable<TFields[N]>[]): Promise<void>;
|
|
10
|
-
private makeCacheKey;
|
|
11
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const entity_1 = require("@expo/entity");
|
|
7
|
-
const invariant_1 = __importDefault(require("invariant"));
|
|
8
|
-
const GenericLocalMemoryCacher_1 = __importDefault(require("./GenericLocalMemoryCacher"));
|
|
9
|
-
class LocalMemoryCacheAdapter extends entity_1.EntityCacheAdapter {
|
|
10
|
-
constructor(entityConfiguration, localMemoryCache) {
|
|
11
|
-
super(entityConfiguration);
|
|
12
|
-
this.genericLocalMemoryCacher = new GenericLocalMemoryCacher_1.default(localMemoryCache);
|
|
13
|
-
}
|
|
14
|
-
async loadManyAsync(fieldName, fieldValues) {
|
|
15
|
-
const localMemoryCacheKeyToFieldValueMapping = new Map(fieldValues.map((fieldValue) => [this.makeCacheKey(fieldName, fieldValue), fieldValue]));
|
|
16
|
-
const cacheResults = await this.genericLocalMemoryCacher.loadManyAsync(Array.from(localMemoryCacheKeyToFieldValueMapping.keys()));
|
|
17
|
-
return (0, entity_1.mapKeys)(cacheResults, (cacheKey) => {
|
|
18
|
-
const fieldValue = localMemoryCacheKeyToFieldValueMapping.get(cacheKey);
|
|
19
|
-
(0, invariant_1.default)(fieldValue !== undefined, 'Unspecified cache key %s returned from generic local memory cacher', cacheKey);
|
|
20
|
-
return fieldValue;
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
async cacheManyAsync(fieldName, objectMap) {
|
|
24
|
-
await this.genericLocalMemoryCacher.cacheManyAsync((0, entity_1.mapKeys)(objectMap, (fieldValue) => this.makeCacheKey(fieldName, fieldValue)));
|
|
25
|
-
}
|
|
26
|
-
async cacheDBMissesAsync(fieldName, fieldValues) {
|
|
27
|
-
await this.genericLocalMemoryCacher.cacheDBMissesAsync(fieldValues.map((fieldValue) => this.makeCacheKey(fieldName, fieldValue)));
|
|
28
|
-
}
|
|
29
|
-
async invalidateManyAsync(fieldName, fieldValues) {
|
|
30
|
-
await this.genericLocalMemoryCacher.invalidateManyAsync(fieldValues.map((fieldValue) => this.makeCacheKey(fieldName, fieldValue)));
|
|
31
|
-
}
|
|
32
|
-
makeCacheKey(fieldName, fieldValue) {
|
|
33
|
-
const columnName = this.entityConfiguration.entityToDBFieldsKeyMapping.get(fieldName);
|
|
34
|
-
(0, invariant_1.default)(columnName, `database field mapping missing for ${String(fieldName)}`);
|
|
35
|
-
const parts = [
|
|
36
|
-
this.entityConfiguration.tableName,
|
|
37
|
-
`${this.entityConfiguration.cacheKeyVersion}`,
|
|
38
|
-
columnName,
|
|
39
|
-
String(fieldValue),
|
|
40
|
-
];
|
|
41
|
-
return this.genericLocalMemoryCacher.makeCacheKey(parts);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.default = LocalMemoryCacheAdapter;
|
|
45
|
-
//# sourceMappingURL=LocalMemoryCacheAdapter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LocalMemoryCacheAdapter.js","sourceRoot":"","sources":["../src/LocalMemoryCacheAdapter.ts"],"names":[],"mappings":";;;;;AAAA,yCAAiG;AACjG,0DAAkC;AAElC,0FAAwF;AAExF,MAAqB,uBAAiC,SAAQ,2BAA2B;IAGvF,YACE,mBAAiD,EACjD,gBAA2C;QAE3C,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAC3B,IAAI,CAAC,wBAAwB,GAAG,IAAI,kCAAwB,CAAC,gBAAgB,CAAC,CAAC;IACjF,CAAC;IAEM,KAAK,CAAC,aAAa,CACxB,SAAY,EACZ,WAA+C;QAE/C,MAAM,sCAAsC,GAAG,IAAI,GAAG,CACpD,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,UAAU,CAAC,E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,CAAC;QAC5E,MAAM,CAAC,WAAW,CAAC,CAAC,aAAa,CAAC;YAChC,MAAM,EAAE,oBAAW,CAAC,IAAI;SACzB,CAAC,CAAC;QAEH,iHAAiH;QACjH,MAAM,aAAa,GAAG,IAAA,SAAM,GAAE,CAAC;QAE/B,MAAM,uBAAuB,GAAG,MAAM,+BAAqB,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,aAAa,CAC7F,aAAa,CACd,CAAC;QACF,MAAM,CAAC,uBAAuB,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAE/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 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
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;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const entity_1 = require("@expo/entity");
|
|
30
|
-
const GenericLocalMemoryCacher_1 = __importStar(require("../GenericLocalMemoryCacher"));
|
|
31
|
-
const LocalMemoryCacheAdapter_1 = __importDefault(require("../LocalMemoryCacheAdapter"));
|
|
32
|
-
const entityConfiguration = new entity_1.EntityConfiguration({
|
|
33
|
-
idField: 'id',
|
|
34
|
-
tableName: 'blah',
|
|
35
|
-
schema: {
|
|
36
|
-
id: new entity_1.UUIDField({ columnName: 'id', cache: true }),
|
|
37
|
-
},
|
|
38
|
-
databaseAdapterFlavor: 'postgres',
|
|
39
|
-
cacheAdapterFlavor: 'local-memory',
|
|
40
|
-
});
|
|
41
|
-
describe(LocalMemoryCacheAdapter_1.default, () => {
|
|
42
|
-
describe('loadManyAsync', () => {
|
|
43
|
-
it('returns appropriate cache results', async () => {
|
|
44
|
-
const cacheAdapter = new LocalMemoryCacheAdapter_1.default(entityConfiguration, GenericLocalMemoryCacher_1.default.createLRUCache());
|
|
45
|
-
const cacheHits = new Map([['test-id-1', { id: 'test-id-1' }]]);
|
|
46
|
-
await cacheAdapter.cacheManyAsync('id', cacheHits);
|
|
47
|
-
await cacheAdapter.cacheDBMissesAsync('id', ['test-id-2']);
|
|
48
|
-
const results = await cacheAdapter.loadManyAsync('id', [
|
|
49
|
-
'test-id-1',
|
|
50
|
-
'test-id-2',
|
|
51
|
-
'test-id-3',
|
|
52
|
-
]);
|
|
53
|
-
expect(results.get('test-id-1')).toMatchObject({
|
|
54
|
-
status: entity_1.CacheStatus.HIT,
|
|
55
|
-
item: { id: 'test-id-1' },
|
|
56
|
-
});
|
|
57
|
-
expect(results.get('test-id-2')).toMatchObject({ status: entity_1.CacheStatus.NEGATIVE });
|
|
58
|
-
expect(results.get('test-id-3')).toMatchObject({ status: entity_1.CacheStatus.MISS });
|
|
59
|
-
expect(results.size).toBe(3);
|
|
60
|
-
});
|
|
61
|
-
it('returns empty map when passed empty array of fieldValues', async () => {
|
|
62
|
-
const cacheAdapter = new LocalMemoryCacheAdapter_1.default(entityConfiguration, GenericLocalMemoryCacher_1.default.createLRUCache());
|
|
63
|
-
const results = await cacheAdapter.loadManyAsync('id', []);
|
|
64
|
-
expect(results).toEqual(new Map());
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
describe('cacheManyAsync', () => {
|
|
68
|
-
it('correctly caches all objects', async () => {
|
|
69
|
-
const localMemoryCache = GenericLocalMemoryCacher_1.default.createLRUCache({});
|
|
70
|
-
const cacheAdapter = new LocalMemoryCacheAdapter_1.default(entityConfiguration, localMemoryCache);
|
|
71
|
-
await cacheAdapter.cacheManyAsync('id', new Map([['test-id-1', { id: 'test-id-1' }]]));
|
|
72
|
-
const cacheKey = cacheAdapter['makeCacheKey']('id', 'test-id-1');
|
|
73
|
-
expect(localMemoryCache.get(cacheKey)).toMatchObject({
|
|
74
|
-
id: 'test-id-1',
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
describe('cacheDBMissesAsync', () => {
|
|
79
|
-
it('correctly caches misses', async () => {
|
|
80
|
-
const localMemoryCache = GenericLocalMemoryCacher_1.default.createLRUCache({});
|
|
81
|
-
const cacheAdapter = new LocalMemoryCacheAdapter_1.default(entityConfiguration, localMemoryCache);
|
|
82
|
-
await cacheAdapter.cacheDBMissesAsync('id', ['test-id-1']);
|
|
83
|
-
const cacheKey = cacheAdapter['makeCacheKey']('id', 'test-id-1');
|
|
84
|
-
expect(localMemoryCache.get(cacheKey)).toEqual(GenericLocalMemoryCacher_1.DOES_NOT_EXIST_LOCAL_MEMORY_CACHE);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
describe('invalidateManyAsync', () => {
|
|
88
|
-
it('invalidates correctly', async () => {
|
|
89
|
-
const localMemoryCache = GenericLocalMemoryCacher_1.default.createLRUCache({});
|
|
90
|
-
const cacheAdapter = new LocalMemoryCacheAdapter_1.default(entityConfiguration, localMemoryCache);
|
|
91
|
-
await cacheAdapter.cacheManyAsync('id', new Map([['test-id-1', { id: 'test-id-1' }]]));
|
|
92
|
-
await cacheAdapter.cacheDBMissesAsync('id', ['test-id-2']);
|
|
93
|
-
await cacheAdapter.invalidateManyAsync('id', ['test-id-1', 'test-id-2']);
|
|
94
|
-
const results = await cacheAdapter.loadManyAsync('id', ['test-id-1', 'test-id-2']);
|
|
95
|
-
expect(results.get('test-id-1')).toMatchObject({ status: entity_1.CacheStatus.MISS });
|
|
96
|
-
expect(results.get('test-id-2')).toMatchObject({ status: entity_1.CacheStatus.MISS });
|
|
97
|
-
});
|
|
98
|
-
it('returns when passed empty array of fieldValues', async () => {
|
|
99
|
-
const cacheAdapter = new LocalMemoryCacheAdapter_1.default(entityConfiguration, GenericLocalMemoryCacher_1.default.createLRUCache({}));
|
|
100
|
-
await cacheAdapter.invalidateManyAsync('id', []);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
//# sourceMappingURL=LocalMemoryCacheAdapter-test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LocalMemoryCacheAdapter-test.js","sourceRoot":"","sources":["../../src/__tests__/LocalMemoryCacheAdapter-test.ts"],"names":[],"mappings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AC,CAAC,CAAC;YAEzE,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC;YACnF,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,oBAAW,CAAC,IAAI,EAAE,CAAC,CAAC;YAC7E,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,oBAAW,CAAC,IAAI,EAAE,CAAC,CAAC;QAC/E,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,gDAAgD,EAAE,KAAK,IAAI,EAAE;YAC9D,MAAM,YAAY,GAAG,IAAI,iCAAuB,CAC9C,mBAAmB,EACnB,kCAAwB,CAAC,cAAc,CAAa,EAAE,CAAC,CACxD,CAAC;YACF,MAAM,YAAY,CAAC,mBAAmB,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { EntityCacheAdapter, CacheLoadResult, EntityConfiguration, mapKeys } from '@expo/entity';
|
|
2
|
-
import invariant from 'invariant';
|
|
3
|
-
|
|
4
|
-
import GenericLocalMemoryCacher, { LocalMemoryCache } from './GenericLocalMemoryCacher';
|
|
5
|
-
|
|
6
|
-
export default class LocalMemoryCacheAdapter<TFields> extends EntityCacheAdapter<TFields> {
|
|
7
|
-
private readonly genericLocalMemoryCacher: GenericLocalMemoryCacher<TFields>;
|
|
8
|
-
|
|
9
|
-
constructor(
|
|
10
|
-
entityConfiguration: EntityConfiguration<TFields>,
|
|
11
|
-
localMemoryCache: LocalMemoryCache<TFields>
|
|
12
|
-
) {
|
|
13
|
-
super(entityConfiguration);
|
|
14
|
-
this.genericLocalMemoryCacher = new GenericLocalMemoryCacher(localMemoryCache);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public async loadManyAsync<N extends keyof TFields>(
|
|
18
|
-
fieldName: N,
|
|
19
|
-
fieldValues: readonly NonNullable<TFields[N]>[]
|
|
20
|
-
): Promise<ReadonlyMap<NonNullable<TFields[N]>, CacheLoadResult<TFields>>> {
|
|
21
|
-
const localMemoryCacheKeyToFieldValueMapping = new Map(
|
|
22
|
-
fieldValues.map((fieldValue) => [this.makeCacheKey(fieldName, fieldValue), fieldValue])
|
|
23
|
-
);
|
|
24
|
-
const cacheResults = await this.genericLocalMemoryCacher.loadManyAsync(
|
|
25
|
-
Array.from(localMemoryCacheKeyToFieldValueMapping.keys())
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
return mapKeys(cacheResults, (cacheKey) => {
|
|
29
|
-
const fieldValue = localMemoryCacheKeyToFieldValueMapping.get(cacheKey);
|
|
30
|
-
invariant(
|
|
31
|
-
fieldValue !== undefined,
|
|
32
|
-
'Unspecified cache key %s returned from generic local memory cacher',
|
|
33
|
-
cacheKey
|
|
34
|
-
);
|
|
35
|
-
return fieldValue;
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public async cacheManyAsync<N extends keyof TFields>(
|
|
40
|
-
fieldName: N,
|
|
41
|
-
objectMap: ReadonlyMap<NonNullable<TFields[N]>, Readonly<TFields>>
|
|
42
|
-
): Promise<void> {
|
|
43
|
-
await this.genericLocalMemoryCacher.cacheManyAsync(
|
|
44
|
-
mapKeys(objectMap, (fieldValue) => this.makeCacheKey(fieldName, fieldValue))
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
public async cacheDBMissesAsync<N extends keyof TFields>(
|
|
49
|
-
fieldName: N,
|
|
50
|
-
fieldValues: readonly NonNullable<TFields[N]>[]
|
|
51
|
-
): Promise<void> {
|
|
52
|
-
await this.genericLocalMemoryCacher.cacheDBMissesAsync(
|
|
53
|
-
fieldValues.map((fieldValue) => this.makeCacheKey(fieldName, fieldValue))
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
public async invalidateManyAsync<N extends keyof TFields>(
|
|
58
|
-
fieldName: N,
|
|
59
|
-
fieldValues: readonly NonNullable<TFields[N]>[]
|
|
60
|
-
): Promise<void> {
|
|
61
|
-
await this.genericLocalMemoryCacher.invalidateManyAsync(
|
|
62
|
-
fieldValues.map((fieldValue) => this.makeCacheKey(fieldName, fieldValue))
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
private makeCacheKey<N extends keyof TFields>(
|
|
67
|
-
fieldName: N,
|
|
68
|
-
fieldValue: NonNullable<TFields[N]>
|
|
69
|
-
): string {
|
|
70
|
-
const columnName = this.entityConfiguration.entityToDBFieldsKeyMapping.get(fieldName);
|
|
71
|
-
invariant(columnName, `database field mapping missing for ${String(fieldName)}`);
|
|
72
|
-
const parts = [
|
|
73
|
-
this.entityConfiguration.tableName,
|
|
74
|
-
`${this.entityConfiguration.cacheKeyVersion}`,
|
|
75
|
-
columnName,
|
|
76
|
-
String(fieldValue),
|
|
77
|
-
];
|
|
78
|
-
return this.genericLocalMemoryCacher.makeCacheKey(parts);
|
|
79
|
-
}
|
|
80
|
-
}
|