@expo/entity-cache-adapter-redis 0.46.0 → 0.48.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/src/RedisCommon.d.ts +17 -0
- package/build/src/RedisCommon.js +21 -0
- package/build/src/RedisCommon.js.map +1 -1
- package/package.json +7 -4
- package/src/RedisCommon.ts +22 -1
- package/src/__integration-tests__/GenericRedisCacher-full-integration-test.ts +25 -0
- package/src/__integration-tests__/GenericRedisCacher-integration-test.ts +6 -0
- package/src/__testfixtures__/RedisTestEntity.ts +7 -0
- package/build/src/__integration-tests__/BatchedRedisCacheAdapter-integration-test.d.ts +0 -1
- package/build/src/__integration-tests__/BatchedRedisCacheAdapter-integration-test.js +0 -125
- package/build/src/__integration-tests__/BatchedRedisCacheAdapter-integration-test.js.map +0 -1
- package/build/src/__integration-tests__/GenericRedisCacher-full-integration-test.d.ts +0 -1
- package/build/src/__integration-tests__/GenericRedisCacher-full-integration-test.js +0 -114
- package/build/src/__integration-tests__/GenericRedisCacher-full-integration-test.js.map +0 -1
- package/build/src/__integration-tests__/GenericRedisCacher-integration-test.d.ts +0 -1
- package/build/src/__integration-tests__/GenericRedisCacher-integration-test.js +0 -93
- package/build/src/__integration-tests__/GenericRedisCacher-integration-test.js.map +0 -1
- package/build/src/__integration-tests__/errors-test.d.ts +0 -1
- package/build/src/__integration-tests__/errors-test.js +0 -43
- package/build/src/__integration-tests__/errors-test.js.map +0 -1
- package/build/src/__testfixtures__/RedisTestEntity.d.ts +0 -16
- package/build/src/__testfixtures__/RedisTestEntity.js +0 -53
- package/build/src/__testfixtures__/RedisTestEntity.js.map +0 -1
- package/build/src/__testfixtures__/createRedisIntegrationTestEntityCompanionProvider.d.ts +0 -3
- package/build/src/__testfixtures__/createRedisIntegrationTestEntityCompanionProvider.js +0 -29
- package/build/src/__testfixtures__/createRedisIntegrationTestEntityCompanionProvider.js.map +0 -1
- package/build/src/__tests__/GenericRedisCacher-test.d.ts +0 -1
- package/build/src/__tests__/GenericRedisCacher-test.js +0 -211
- package/build/src/__tests__/GenericRedisCacher-test.js.map +0 -1
- package/build/src/errors/__tests__/wrapNativeRedisCallAsync-test.d.ts +0 -1
- package/build/src/errors/__tests__/wrapNativeRedisCallAsync-test.js +0 -40
- package/build/src/errors/__tests__/wrapNativeRedisCallAsync-test.js.map +0 -1
- package/build/src/utils/__tests__/getSurroundingCacheKeyVersionsForInvalidation-test.d.ts +0 -1
- package/build/src/utils/__tests__/getSurroundingCacheKeyVersionsForInvalidation-test.js +0 -12
- package/build/src/utils/__tests__/getSurroundingCacheKeyVersionsForInvalidation-test.js.map +0 -1
- package/build/tsconfig.tsbuildinfo +0 -1
|
@@ -15,4 +15,21 @@ export declare const redisTransformerMap: Map<string, {
|
|
|
15
15
|
*/
|
|
16
16
|
write: (val: Date) => string;
|
|
17
17
|
read: (val: any) => any;
|
|
18
|
+
} | {
|
|
19
|
+
/**
|
|
20
|
+
* All Redis fields are serialized to JSON before being written.
|
|
21
|
+
* In the case of buffers, they need to be explicitly reconstructed
|
|
22
|
+
* as JavaScript Buffer objects upon retrieval. We also explicitly
|
|
23
|
+
* serialize them to base64 strings to ensure no underlying Redis
|
|
24
|
+
* changes affect the fields.
|
|
25
|
+
*
|
|
26
|
+
* Write behavior: Value to write will always be either a Buffer or null.
|
|
27
|
+
* Behavior is to pass through null and convert buffers
|
|
28
|
+
* to base64 strings.
|
|
29
|
+
* Read behavior: Value will always be either null or a base64 string.
|
|
30
|
+
* behavior is to convert base64 strings back into Buffer
|
|
31
|
+
* objects and pass through null.
|
|
32
|
+
*/
|
|
33
|
+
write: (val: Buffer) => string | null;
|
|
34
|
+
read: (val: any) => any;
|
|
18
35
|
}>;
|
package/build/src/RedisCommon.js
CHANGED
|
@@ -24,5 +24,26 @@ exports.redisTransformerMap = new Map([
|
|
|
24
24
|
read: (val) => (val ? new Date(val) : val),
|
|
25
25
|
},
|
|
26
26
|
],
|
|
27
|
+
[
|
|
28
|
+
entity_1.BufferField.name,
|
|
29
|
+
{
|
|
30
|
+
/**
|
|
31
|
+
* All Redis fields are serialized to JSON before being written.
|
|
32
|
+
* In the case of buffers, they need to be explicitly reconstructed
|
|
33
|
+
* as JavaScript Buffer objects upon retrieval. We also explicitly
|
|
34
|
+
* serialize them to base64 strings to ensure no underlying Redis
|
|
35
|
+
* changes affect the fields.
|
|
36
|
+
*
|
|
37
|
+
* Write behavior: Value to write will always be either a Buffer or null.
|
|
38
|
+
* Behavior is to pass through null and convert buffers
|
|
39
|
+
* to base64 strings.
|
|
40
|
+
* Read behavior: Value will always be either null or a base64 string.
|
|
41
|
+
* behavior is to convert base64 strings back into Buffer
|
|
42
|
+
* objects and pass through null.
|
|
43
|
+
*/
|
|
44
|
+
write: (val) => (val ? val.toString('base64') : null),
|
|
45
|
+
read: (val) => (val ? Buffer.from(val, 'base64') : val),
|
|
46
|
+
},
|
|
47
|
+
],
|
|
27
48
|
]);
|
|
28
49
|
//# sourceMappingURL=RedisCommon.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RedisCommon.js","sourceRoot":"","sources":["../../src/RedisCommon.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"RedisCommon.js","sourceRoot":"","sources":["../../src/RedisCommon.ts"],"names":[],"mappings":";;;AAAA,yCAAsD;AAEzC,QAAA,mBAAmB,GAAG,IAAI,GAAG,CAAC;IACzC;QACE,kBAAS,CAAC,IAAI;QACd;YACE;;;;;;;;;;;;;eAaG;YACH,KAAK,EAAE,CAAC,GAAS,EAAE,EAAE,CAAC,GAAG,EAAE,WAAW,EAAE,IAAI,IAAI;YAChD,IAAI,EAAE,CAAC,GAAQ,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;SAChD;KACF;IACD;QACE,oBAAW,CAAC,IAAI;QAChB;YACE;;;;;;;;;;;;;eAaG;YACH,KAAK,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YAC7D,IAAI,EAAE,CAAC,GAAQ,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;SAC7D;KACF;CACF,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expo/entity-cache-adapter-redis",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.48.0",
|
|
4
4
|
"description": "Redis cache adapter for @expo/entity",
|
|
5
5
|
"files": [
|
|
6
6
|
"build",
|
|
7
|
+
"!*.tsbuildinfo",
|
|
8
|
+
"!__*",
|
|
7
9
|
"src"
|
|
8
10
|
],
|
|
9
11
|
"main": "build/src/index.js",
|
|
10
12
|
"types": "build/src/index.d.ts",
|
|
11
13
|
"scripts": {
|
|
12
14
|
"build": "tsc --build",
|
|
15
|
+
"prepack": "rm -rf build && yarn build",
|
|
13
16
|
"clean": "yarn build --clean",
|
|
14
17
|
"lint": "yarn run --top-level eslint src",
|
|
15
18
|
"lint-fix": "yarn lint --fix",
|
|
@@ -25,18 +28,18 @@
|
|
|
25
28
|
"author": "Expo",
|
|
26
29
|
"license": "MIT",
|
|
27
30
|
"dependencies": {
|
|
28
|
-
"@expo/entity": "^0.
|
|
31
|
+
"@expo/entity": "^0.48.0"
|
|
29
32
|
},
|
|
30
33
|
"peerDependencies": {
|
|
31
34
|
"ioredis": ">=5"
|
|
32
35
|
},
|
|
33
36
|
"devDependencies": {
|
|
34
37
|
"@expo/batcher": "^1.0.0",
|
|
35
|
-
"@expo/entity-testing-utils": "^0.
|
|
38
|
+
"@expo/entity-testing-utils": "^0.48.0",
|
|
36
39
|
"@jest/globals": "^30.0.0",
|
|
37
40
|
"ioredis": "^5.6.0",
|
|
38
41
|
"ts-mockito": "^2.6.1",
|
|
39
42
|
"typescript": "^5.8.3"
|
|
40
43
|
},
|
|
41
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "7b4bec8f841fecdb30af306441b540c0efae1603"
|
|
42
45
|
}
|
package/src/RedisCommon.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DateField } from '@expo/entity';
|
|
1
|
+
import { BufferField, DateField } from '@expo/entity';
|
|
2
2
|
|
|
3
3
|
export const redisTransformerMap = new Map([
|
|
4
4
|
[
|
|
@@ -22,4 +22,25 @@ export const redisTransformerMap = new Map([
|
|
|
22
22
|
read: (val: any) => (val ? new Date(val) : val),
|
|
23
23
|
},
|
|
24
24
|
],
|
|
25
|
+
[
|
|
26
|
+
BufferField.name,
|
|
27
|
+
{
|
|
28
|
+
/**
|
|
29
|
+
* All Redis fields are serialized to JSON before being written.
|
|
30
|
+
* In the case of buffers, they need to be explicitly reconstructed
|
|
31
|
+
* as JavaScript Buffer objects upon retrieval. We also explicitly
|
|
32
|
+
* serialize them to base64 strings to ensure no underlying Redis
|
|
33
|
+
* changes affect the fields.
|
|
34
|
+
*
|
|
35
|
+
* Write behavior: Value to write will always be either a Buffer or null.
|
|
36
|
+
* Behavior is to pass through null and convert buffers
|
|
37
|
+
* to base64 strings.
|
|
38
|
+
* Read behavior: Value will always be either null or a base64 string.
|
|
39
|
+
* behavior is to convert base64 strings back into Buffer
|
|
40
|
+
* objects and pass through null.
|
|
41
|
+
*/
|
|
42
|
+
write: (val: Buffer) => (val ? val.toString('base64') : null),
|
|
43
|
+
read: (val: any) => (val ? Buffer.from(val, 'base64') : val),
|
|
44
|
+
},
|
|
45
|
+
],
|
|
25
46
|
]);
|
|
@@ -64,6 +64,8 @@ describe(GenericRedisCacher, () => {
|
|
|
64
64
|
|
|
65
65
|
const entity1Created = await RedisTestEntity.creator(viewerContext)
|
|
66
66
|
.setField('name', 'blah')
|
|
67
|
+
.setField('dateField', new Date())
|
|
68
|
+
.setField('bufferField', Buffer.from('hello world'))
|
|
67
69
|
.createAsync();
|
|
68
70
|
|
|
69
71
|
// loading an entity should put it in cache
|
|
@@ -207,4 +209,27 @@ describe(GenericRedisCacher, () => {
|
|
|
207
209
|
const entity3 = await RedisTestEntity.loader(vc2).loadByFieldEqualingAsync('name', '');
|
|
208
210
|
expect(entity3?.getID()).toEqual(entity1.getID());
|
|
209
211
|
});
|
|
212
|
+
|
|
213
|
+
it('caches and restores buffer fields', async () => {
|
|
214
|
+
const viewerContext = new TestViewerContext(
|
|
215
|
+
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext),
|
|
216
|
+
);
|
|
217
|
+
const buffer = Buffer.from('hello world');
|
|
218
|
+
const entity1 = await enforceAsyncResult(
|
|
219
|
+
RedisTestEntity.creatorWithAuthorizationResults(viewerContext)
|
|
220
|
+
.setField('bufferField', buffer)
|
|
221
|
+
.createAsync(),
|
|
222
|
+
);
|
|
223
|
+
expect(entity1.getField('bufferField')).toEqual(buffer);
|
|
224
|
+
|
|
225
|
+
const entity2 = await RedisTestEntity.loader(viewerContext).loadByIDAsync(entity1.getID());
|
|
226
|
+
expect(entity2.getField('bufferField')).toEqual(buffer);
|
|
227
|
+
|
|
228
|
+
// simulate new request
|
|
229
|
+
const vc2 = new TestViewerContext(
|
|
230
|
+
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext),
|
|
231
|
+
);
|
|
232
|
+
const entity3 = await RedisTestEntity.loader(vc2).loadByIDAsync(entity1.getID());
|
|
233
|
+
expect(entity3.getField('bufferField')).toEqual(buffer);
|
|
234
|
+
});
|
|
210
235
|
});
|
|
@@ -55,9 +55,11 @@ describe(GenericRedisCacher, () => {
|
|
|
55
55
|
redisTestEntityConfiguration,
|
|
56
56
|
);
|
|
57
57
|
const date = new Date();
|
|
58
|
+
const buffer = Buffer.from('hello world');
|
|
58
59
|
const entity1Created = await RedisTestEntity.creator(viewerContext)
|
|
59
60
|
.setField('name', 'blah')
|
|
60
61
|
.setField('dateField', date)
|
|
62
|
+
.setField('bufferField', buffer)
|
|
61
63
|
.createAsync();
|
|
62
64
|
const testKey = `test-id-key-${entity1Created.getID()}`;
|
|
63
65
|
const objectMap = new Map<string, Readonly<RedisTestEntityFields>>([
|
|
@@ -80,6 +82,7 @@ describe(GenericRedisCacher, () => {
|
|
|
80
82
|
});
|
|
81
83
|
expect(loadedObjectMap.size).toBe(1);
|
|
82
84
|
});
|
|
85
|
+
|
|
83
86
|
it('has correct negative caching behaviour', async () => {
|
|
84
87
|
const genericRedisCacher = new GenericRedisCacher(
|
|
85
88
|
genericRedisCacheContext,
|
|
@@ -92,6 +95,7 @@ describe(GenericRedisCacher, () => {
|
|
|
92
95
|
const cacheLoadResult = loadedObjectMap.get(testKey)!;
|
|
93
96
|
expect(cacheLoadResult.status).toBe(CacheStatus.NEGATIVE);
|
|
94
97
|
});
|
|
98
|
+
|
|
95
99
|
it('has correct invalidation behaviour', async () => {
|
|
96
100
|
const viewerContext = new TestViewerContext(
|
|
97
101
|
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext),
|
|
@@ -101,9 +105,11 @@ describe(GenericRedisCacher, () => {
|
|
|
101
105
|
redisTestEntityConfiguration,
|
|
102
106
|
);
|
|
103
107
|
const date = new Date();
|
|
108
|
+
const buffer = Buffer.from('hello world');
|
|
104
109
|
const entity1Created = await RedisTestEntity.creator(viewerContext)
|
|
105
110
|
.setField('name', 'blah')
|
|
106
111
|
.setField('dateField', date)
|
|
112
|
+
.setField('bufferField', buffer)
|
|
107
113
|
.createAsync();
|
|
108
114
|
const testKey = `test-id-key-${entity1Created.getID()}`;
|
|
109
115
|
const objectMap = new Map<string, Readonly<RedisTestEntityFields>>([
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AlwaysAllowPrivacyPolicyRule,
|
|
3
|
+
BufferField,
|
|
3
4
|
DateField,
|
|
4
5
|
Entity,
|
|
5
6
|
EntityCompanionDefinition,
|
|
@@ -14,6 +15,7 @@ export type RedisTestEntityFields = {
|
|
|
14
15
|
id: string;
|
|
15
16
|
name: string;
|
|
16
17
|
dateField: Date | null;
|
|
18
|
+
bufferField: Buffer | null;
|
|
17
19
|
};
|
|
18
20
|
|
|
19
21
|
export class RedisTestEntity extends Entity<RedisTestEntityFields, 'id', ViewerContext> {
|
|
@@ -67,11 +69,16 @@ export const redisTestEntityConfiguration = new EntityConfiguration<RedisTestEnt
|
|
|
67
69
|
dateField: new DateField({
|
|
68
70
|
columnName: 'date_field',
|
|
69
71
|
}),
|
|
72
|
+
bufferField: new BufferField({
|
|
73
|
+
columnName: 'buffer_field',
|
|
74
|
+
cache: true,
|
|
75
|
+
}),
|
|
70
76
|
},
|
|
71
77
|
databaseAdapterFlavor: 'postgres',
|
|
72
78
|
cacheAdapterFlavor: 'redis',
|
|
73
79
|
compositeFieldDefinitions: [
|
|
74
80
|
{ compositeField: ['id', 'name'], cache: true },
|
|
75
81
|
{ compositeField: ['id', 'dateField'], cache: true },
|
|
82
|
+
{ compositeField: ['id', 'bufferField'], cache: true },
|
|
76
83
|
],
|
|
77
84
|
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,125 +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 batcher_1 = require("@expo/batcher");
|
|
7
|
-
const entity_1 = require("@expo/entity");
|
|
8
|
-
const globals_1 = require("@jest/globals");
|
|
9
|
-
const invariant_1 = __importDefault(require("invariant"));
|
|
10
|
-
const ioredis_1 = __importDefault(require("ioredis"));
|
|
11
|
-
const nullthrows_1 = __importDefault(require("nullthrows"));
|
|
12
|
-
const url_1 = require("url");
|
|
13
|
-
const uuid_1 = require("uuid");
|
|
14
|
-
const GenericRedisCacher_1 = require("../GenericRedisCacher");
|
|
15
|
-
const RedisTestEntity_1 = require("../__testfixtures__/RedisTestEntity");
|
|
16
|
-
const createRedisIntegrationTestEntityCompanionProvider_1 = require("../__testfixtures__/createRedisIntegrationTestEntityCompanionProvider");
|
|
17
|
-
class BatchedRedis {
|
|
18
|
-
redis;
|
|
19
|
-
mgetBatcher = new batcher_1.Batcher(this.batchMgetAsync.bind(this), {
|
|
20
|
-
maxBatchInterval: 0,
|
|
21
|
-
});
|
|
22
|
-
constructor(redis) {
|
|
23
|
-
this.redis = redis;
|
|
24
|
-
}
|
|
25
|
-
async batchMgetAsync(keySets) {
|
|
26
|
-
// ordered distinct keys to fetch
|
|
27
|
-
const allKeysToFetch = [...new Set(keySets.flat())];
|
|
28
|
-
// fetch the distinct keys
|
|
29
|
-
const allResults = await this.redis.mget(...allKeysToFetch);
|
|
30
|
-
// put them into a map for fast lookup
|
|
31
|
-
const keysToResults = (0, entity_1.zipToMap)(allKeysToFetch, allResults);
|
|
32
|
-
// re-associate them with original key sets
|
|
33
|
-
return keySets.map((keySet) => keySet.map((key) => {
|
|
34
|
-
const result = keysToResults.get(key);
|
|
35
|
-
(0, invariant_1.default)(result !== undefined, 'result should not be undefined');
|
|
36
|
-
return result;
|
|
37
|
-
}));
|
|
38
|
-
}
|
|
39
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
40
|
-
async mget(...args) {
|
|
41
|
-
return await this.mgetBatcher.batchAsync(args);
|
|
42
|
-
}
|
|
43
|
-
multi() {
|
|
44
|
-
return this.redis.multi();
|
|
45
|
-
}
|
|
46
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
47
|
-
async del(...args) {
|
|
48
|
-
await this.redis.del(...args);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
(0, globals_1.describe)(GenericRedisCacher_1.GenericRedisCacher, () => {
|
|
52
|
-
const redis = new ioredis_1.default(new url_1.URL(process.env['REDIS_URL']).toString());
|
|
53
|
-
const redisClient = new BatchedRedis(redis);
|
|
54
|
-
let genericRedisCacheContext;
|
|
55
|
-
(0, globals_1.beforeAll)(() => {
|
|
56
|
-
genericRedisCacheContext = {
|
|
57
|
-
redisClient,
|
|
58
|
-
makeKeyFn(...parts) {
|
|
59
|
-
const delimiter = ':';
|
|
60
|
-
const escapedParts = parts.map((part) => part.replace('\\', '\\\\').replace(delimiter, `\\${delimiter}`));
|
|
61
|
-
return escapedParts.join(delimiter);
|
|
62
|
-
},
|
|
63
|
-
cacheKeyPrefix: 'test-',
|
|
64
|
-
ttlSecondsPositive: 86400, // 1 day
|
|
65
|
-
ttlSecondsNegative: 600, // 10 minutes
|
|
66
|
-
invalidationConfig: {
|
|
67
|
-
invalidationStrategy: GenericRedisCacher_1.RedisCacheInvalidationStrategy.CURRENT_CACHE_KEY_VERSION,
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
});
|
|
71
|
-
(0, globals_1.beforeEach)(async () => {
|
|
72
|
-
await redis.flushdb();
|
|
73
|
-
});
|
|
74
|
-
(0, globals_1.afterAll)(async () => {
|
|
75
|
-
redis.disconnect();
|
|
76
|
-
});
|
|
77
|
-
(0, globals_1.it)('has correct caching behavior', async () => {
|
|
78
|
-
// simulate two requests
|
|
79
|
-
const viewerContext = new entity_1.ViewerContext((0, createRedisIntegrationTestEntityCompanionProvider_1.createRedisIntegrationTestEntityCompanionProvider)(genericRedisCacheContext));
|
|
80
|
-
const mgetSpy = globals_1.jest.spyOn(redis, 'mget');
|
|
81
|
-
const genericCacher = viewerContext.entityCompanionProvider.getCompanionForEntity(RedisTestEntity_1.RedisTestEntity)['tableDataCoordinator']['cacheAdapter']['genericCacher'];
|
|
82
|
-
const entity1Created = await RedisTestEntity_1.RedisTestEntity.creator(viewerContext)
|
|
83
|
-
.setField('name', 'blah')
|
|
84
|
-
.createAsync();
|
|
85
|
-
// loading an entity should put it in cache. load by multiple requests and multiple fields in same tick to ensure batch works
|
|
86
|
-
mgetSpy.mockClear();
|
|
87
|
-
const viewerContext1 = new entity_1.ViewerContext((0, createRedisIntegrationTestEntityCompanionProvider_1.createRedisIntegrationTestEntityCompanionProvider)(genericRedisCacheContext));
|
|
88
|
-
const viewerContext2 = new entity_1.ViewerContext((0, createRedisIntegrationTestEntityCompanionProvider_1.createRedisIntegrationTestEntityCompanionProvider)(genericRedisCacheContext));
|
|
89
|
-
const viewerContext3 = new entity_1.ViewerContext((0, createRedisIntegrationTestEntityCompanionProvider_1.createRedisIntegrationTestEntityCompanionProvider)(genericRedisCacheContext));
|
|
90
|
-
const [entity1, entity2, entity3] = await Promise.all([
|
|
91
|
-
RedisTestEntity_1.RedisTestEntity.loader(viewerContext1).loadByIDAsync(entity1Created.getID()),
|
|
92
|
-
RedisTestEntity_1.RedisTestEntity.loader(viewerContext2).loadByIDAsync(entity1Created.getID()),
|
|
93
|
-
RedisTestEntity_1.RedisTestEntity.loader(viewerContext3).loadByFieldEqualingAsync('name', entity1Created.getField('name')),
|
|
94
|
-
]);
|
|
95
|
-
(0, globals_1.expect)(mgetSpy).toHaveBeenCalledTimes(1);
|
|
96
|
-
(0, globals_1.expect)(mgetSpy.mock.calls[0]).toHaveLength(2); // should dedupe the first two loads
|
|
97
|
-
(0, globals_1.expect)(entity1.getID()).toEqual(entity2.getID());
|
|
98
|
-
(0, globals_1.expect)(entity2.getID()).toEqual((0, nullthrows_1.default)(entity3).getID());
|
|
99
|
-
const cacheKeyEntity1 = genericCacher.makeCacheKeyForStorage(new entity_1.SingleFieldHolder('id'), new entity_1.SingleFieldValueHolder(entity1Created.getID()));
|
|
100
|
-
const cachedJSON = await redis.get(cacheKeyEntity1);
|
|
101
|
-
const cachedValue = JSON.parse(cachedJSON);
|
|
102
|
-
(0, globals_1.expect)(cachedValue).toMatchObject({
|
|
103
|
-
id: entity1.getID(),
|
|
104
|
-
name: 'blah',
|
|
105
|
-
});
|
|
106
|
-
const cacheKeyEntity1NameField = genericCacher.makeCacheKeyForStorage(new entity_1.SingleFieldHolder('name'), new entity_1.SingleFieldValueHolder(entity1Created.getField('name')));
|
|
107
|
-
await RedisTestEntity_1.RedisTestEntity.loader(viewerContext).loadByFieldEqualingAsync('name', entity1Created.getField('name'));
|
|
108
|
-
await (0, globals_1.expect)(redis.get(cacheKeyEntity1NameField)).resolves.toEqual(cachedJSON);
|
|
109
|
-
// simulate non existent db fetch, should write negative result ('') to cache
|
|
110
|
-
const nonExistentId = (0, uuid_1.v4)();
|
|
111
|
-
const entityNonExistentResult = await RedisTestEntity_1.RedisTestEntity.loaderWithAuthorizationResults(viewerContext).loadByIDAsync(nonExistentId);
|
|
112
|
-
(0, globals_1.expect)(entityNonExistentResult.ok).toBe(false);
|
|
113
|
-
const cacheKeyNonExistent = genericCacher.makeCacheKeyForStorage(new entity_1.SingleFieldHolder('id'), new entity_1.SingleFieldValueHolder(nonExistentId));
|
|
114
|
-
const nonExistentCachedValue = await redis.get(cacheKeyNonExistent);
|
|
115
|
-
(0, globals_1.expect)(nonExistentCachedValue).toEqual('');
|
|
116
|
-
// load again through entities framework to ensure it reads negative result
|
|
117
|
-
const entityNonExistentResult2 = await RedisTestEntity_1.RedisTestEntity.loaderWithAuthorizationResults(viewerContext).loadByIDAsync(nonExistentId);
|
|
118
|
-
(0, globals_1.expect)(entityNonExistentResult2.ok).toBe(false);
|
|
119
|
-
// invalidate from cache to ensure it invalidates correctly in both caches
|
|
120
|
-
await RedisTestEntity_1.RedisTestEntity.loaderUtils(viewerContext).invalidateFieldsAsync(entity1.getAllFields());
|
|
121
|
-
await (0, globals_1.expect)(redis.get(cacheKeyEntity1)).resolves.toBeNull();
|
|
122
|
-
await (0, globals_1.expect)(redis.get(cacheKeyEntity1NameField)).resolves.toBeNull();
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
//# sourceMappingURL=BatchedRedisCacheAdapter-integration-test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BatchedRedisCacheAdapter-integration-test.js","sourceRoot":"","sources":["../../../src/__integration-tests__/BatchedRedisCacheAdapter-integration-test.ts"],"names":[],"mappings":";;;;;AAAA,2CAAwC;AACxC,yCAMsB;AACtB,2CAA4F;AAC5F,0DAAkC;AAClC,sDAA4B;AAC5B,4DAAoC;AACpC,6BAA0B;AAC1B,+BAAoC;AAEpC,8DAM+B;AAC/B,yEAA6F;AAC7F,6IAA0I;AAE1I,MAAM,YAAY;IAQa;IAPZ,WAAW,GAAG,IAAI,iBAAO,CACxC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAC9B;QACE,gBAAgB,EAAE,CAAC;KACpB,CACF,CAAC;IAEF,YAA6B,KAAY;QAAZ,UAAK,GAAL,KAAK,CAAO;IAAG,CAAC;IAErC,KAAK,CAAC,cAAc,CAAC,OAAmB;QAC9C,iCAAiC;QACjC,MAAM,cAAc,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QAEpD,0BAA0B;QAC1B,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC,CAAC;QAE5D,sCAAsC;QACtC,MAAM,aAAa,GAAG,IAAA,iBAAQ,EAAC,cAAc,EAAE,UAAU,CAAC,CAAC;QAE3D,2CAA2C;QAC3C,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAC5B,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;YACjB,MAAM,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACtC,IAAA,mBAAS,EAAC,MAAM,KAAK,SAAS,EAAE,gCAAgC,CAAC,CAAC;YAClE,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAED,gEAAgE;IAChE,KAAK,CAAC,IAAI,CAAC,GAAG,IAAc;QAC1B,OA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Q,CAAC,QAAQ,EAAE,CAAC;QAC7D,MAAM,IAAA,gBAAM,EAAC,KAAK,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;IACxE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,114 +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 results_1 = require("@expo/results");
|
|
8
|
-
const globals_1 = require("@jest/globals");
|
|
9
|
-
const ioredis_1 = __importDefault(require("ioredis"));
|
|
10
|
-
const url_1 = require("url");
|
|
11
|
-
const uuid_1 = require("uuid");
|
|
12
|
-
const GenericRedisCacher_1 = require("../GenericRedisCacher");
|
|
13
|
-
const RedisTestEntity_1 = require("../__testfixtures__/RedisTestEntity");
|
|
14
|
-
const createRedisIntegrationTestEntityCompanionProvider_1 = require("../__testfixtures__/createRedisIntegrationTestEntityCompanionProvider");
|
|
15
|
-
class TestViewerContext extends entity_1.ViewerContext {
|
|
16
|
-
}
|
|
17
|
-
(0, globals_1.describe)(GenericRedisCacher_1.GenericRedisCacher, () => {
|
|
18
|
-
let genericRedisCacheContext;
|
|
19
|
-
(0, globals_1.beforeAll)(() => {
|
|
20
|
-
genericRedisCacheContext = {
|
|
21
|
-
redisClient: new ioredis_1.default(new url_1.URL(process.env['REDIS_URL']).toString()),
|
|
22
|
-
makeKeyFn(...parts) {
|
|
23
|
-
const delimiter = ':';
|
|
24
|
-
const escapedParts = parts.map((part) => part.replace('\\', '\\\\').replace(delimiter, `\\${delimiter}`));
|
|
25
|
-
return escapedParts.join(delimiter);
|
|
26
|
-
},
|
|
27
|
-
cacheKeyPrefix: 'test-',
|
|
28
|
-
ttlSecondsPositive: 86400, // 1 day
|
|
29
|
-
ttlSecondsNegative: 600, // 10 minutes
|
|
30
|
-
invalidationConfig: {
|
|
31
|
-
invalidationStrategy: GenericRedisCacher_1.RedisCacheInvalidationStrategy.CURRENT_CACHE_KEY_VERSION,
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
});
|
|
35
|
-
(0, globals_1.beforeEach)(async () => {
|
|
36
|
-
await genericRedisCacheContext.redisClient.flushdb();
|
|
37
|
-
});
|
|
38
|
-
(0, globals_1.afterAll)(async () => {
|
|
39
|
-
genericRedisCacheContext.redisClient.disconnect();
|
|
40
|
-
});
|
|
41
|
-
(0, globals_1.it)('has correct caching behavior', async () => {
|
|
42
|
-
const viewerContext = new TestViewerContext((0, createRedisIntegrationTestEntityCompanionProvider_1.createRedisIntegrationTestEntityCompanionProvider)(genericRedisCacheContext));
|
|
43
|
-
const genericCacher = viewerContext.entityCompanionProvider.getCompanionForEntity(RedisTestEntity_1.RedisTestEntity)['tableDataCoordinator']['cacheAdapter']['genericCacher'];
|
|
44
|
-
const entity1Created = await RedisTestEntity_1.RedisTestEntity.creator(viewerContext)
|
|
45
|
-
.setField('name', 'blah')
|
|
46
|
-
.createAsync();
|
|
47
|
-
// loading an entity should put it in cache
|
|
48
|
-
const entity1 = await RedisTestEntity_1.RedisTestEntity.loader(viewerContext).loadByIDAsync(entity1Created.getID());
|
|
49
|
-
const cachedSingleJSON = await genericRedisCacheContext.redisClient.get(genericCacher.makeCacheKeyForStorage(new entity_1.SingleFieldHolder('id'), new entity_1.SingleFieldValueHolder(entity1.getID())));
|
|
50
|
-
const cachedSingleValue = JSON.parse(cachedSingleJSON);
|
|
51
|
-
(0, globals_1.expect)(cachedSingleValue).toMatchObject({
|
|
52
|
-
id: entity1.getID(),
|
|
53
|
-
name: 'blah',
|
|
54
|
-
});
|
|
55
|
-
// loading an entity by composite field should put it in cache
|
|
56
|
-
const entity2 = await RedisTestEntity_1.RedisTestEntity.loader(viewerContext).loadByCompositeFieldEqualingAsync(['name', 'id'], { name: 'blah', id: entity1.getID() });
|
|
57
|
-
const cachedCompositeJSON = await genericRedisCacheContext.redisClient.get(genericCacher.makeCacheKeyForStorage(new entity_1.CompositeFieldHolder(['id', 'name']), new entity_1.CompositeFieldValueHolder({ id: entity2.getID(), name: 'blah' })));
|
|
58
|
-
const cachedCompositeValue = JSON.parse(cachedCompositeJSON);
|
|
59
|
-
(0, globals_1.expect)(cachedCompositeValue).toMatchObject({
|
|
60
|
-
id: entity2.getID(),
|
|
61
|
-
name: 'blah',
|
|
62
|
-
});
|
|
63
|
-
// simulate non existent db fetch, should write negative result ('') to cache
|
|
64
|
-
const nonExistentId = (0, uuid_1.v4)();
|
|
65
|
-
const entityNonExistentResult = await RedisTestEntity_1.RedisTestEntity.loaderWithAuthorizationResults(viewerContext).loadByIDAsync(nonExistentId);
|
|
66
|
-
(0, globals_1.expect)(entityNonExistentResult.ok).toBe(false);
|
|
67
|
-
const nonExistentCachedValue = await genericRedisCacheContext.redisClient.get(genericCacher.makeCacheKeyForStorage(new entity_1.SingleFieldHolder('id'), new entity_1.SingleFieldValueHolder(nonExistentId)));
|
|
68
|
-
(0, globals_1.expect)(nonExistentCachedValue).toEqual('');
|
|
69
|
-
const entityNonExistentCompositeResult = await RedisTestEntity_1.RedisTestEntity.loader(viewerContext).loadByCompositeFieldEqualingAsync(['name', 'id'], { name: 'blah', id: nonExistentId });
|
|
70
|
-
(0, globals_1.expect)(entityNonExistentCompositeResult).toBe(null);
|
|
71
|
-
const nonExistentCompositeCachedValue = await genericRedisCacheContext.redisClient.get(genericCacher.makeCacheKeyForStorage(new entity_1.CompositeFieldHolder(['id', 'name']), new entity_1.CompositeFieldValueHolder({ id: nonExistentId, name: 'blah' })));
|
|
72
|
-
(0, globals_1.expect)(nonExistentCompositeCachedValue).toEqual('');
|
|
73
|
-
// load again through entities framework to ensure it reads negative result
|
|
74
|
-
const entityNonExistentResult2 = await RedisTestEntity_1.RedisTestEntity.loaderWithAuthorizationResults(viewerContext).loadByIDAsync(nonExistentId);
|
|
75
|
-
(0, globals_1.expect)(entityNonExistentResult2.ok).toBe(false);
|
|
76
|
-
const entityNonExistentCompositeResult2 = await RedisTestEntity_1.RedisTestEntity.loader(viewerContext).loadByCompositeFieldEqualingAsync(['name', 'id'], { name: 'blah', id: nonExistentId });
|
|
77
|
-
(0, globals_1.expect)(entityNonExistentCompositeResult2).toBe(null);
|
|
78
|
-
// invalidate from cache to ensure it invalidates correctly
|
|
79
|
-
await RedisTestEntity_1.RedisTestEntity.loaderUtils(viewerContext).invalidateFieldsAsync(entity1.getAllFields());
|
|
80
|
-
const cachedValueNullKeys = genericCacher.makeCacheKeysForInvalidation(new entity_1.SingleFieldHolder('id'), new entity_1.SingleFieldValueHolder(entity1.getID()));
|
|
81
|
-
const cachedValueNull = await genericRedisCacheContext.redisClient.mget(...cachedValueNullKeys);
|
|
82
|
-
(0, globals_1.expect)(cachedValueNull.every((c) => c === null)).toBe(true);
|
|
83
|
-
const cachedValueNullCompositeKeys = genericCacher.makeCacheKeysForInvalidation(new entity_1.CompositeFieldHolder(['id', 'name']), new entity_1.CompositeFieldValueHolder({ id: entity1.getID(), name: 'blah' }));
|
|
84
|
-
const cachedValueNullComposite = await genericRedisCacheContext.redisClient.mget(...cachedValueNullCompositeKeys);
|
|
85
|
-
(0, globals_1.expect)(cachedValueNullComposite.every((c) => c === null)).toBe(true);
|
|
86
|
-
});
|
|
87
|
-
(0, globals_1.it)('caches and restores date fields', async () => {
|
|
88
|
-
const viewerContext = new TestViewerContext((0, createRedisIntegrationTestEntityCompanionProvider_1.createRedisIntegrationTestEntityCompanionProvider)(genericRedisCacheContext));
|
|
89
|
-
const date = new Date();
|
|
90
|
-
const entity1 = await (0, results_1.enforceAsyncResult)(RedisTestEntity_1.RedisTestEntity.creatorWithAuthorizationResults(viewerContext)
|
|
91
|
-
.setField('dateField', date)
|
|
92
|
-
.createAsync());
|
|
93
|
-
(0, globals_1.expect)(entity1.getField('dateField')).toEqual(date);
|
|
94
|
-
const entity2 = await RedisTestEntity_1.RedisTestEntity.loader(viewerContext).loadByIDAsync(entity1.getID());
|
|
95
|
-
(0, globals_1.expect)(entity2.getField('dateField')).toEqual(date);
|
|
96
|
-
// simulate new request
|
|
97
|
-
const vc2 = new TestViewerContext((0, createRedisIntegrationTestEntityCompanionProvider_1.createRedisIntegrationTestEntityCompanionProvider)(genericRedisCacheContext));
|
|
98
|
-
const entity3 = await RedisTestEntity_1.RedisTestEntity.loader(vc2).loadByIDAsync(entity1.getID());
|
|
99
|
-
(0, globals_1.expect)(entity3.getField('dateField')).toEqual(date);
|
|
100
|
-
});
|
|
101
|
-
(0, globals_1.it)('caches and restores empty string field keys', async () => {
|
|
102
|
-
const viewerContext = new TestViewerContext((0, createRedisIntegrationTestEntityCompanionProvider_1.createRedisIntegrationTestEntityCompanionProvider)(genericRedisCacheContext));
|
|
103
|
-
const entity1 = await (0, results_1.enforceAsyncResult)(RedisTestEntity_1.RedisTestEntity.creatorWithAuthorizationResults(viewerContext)
|
|
104
|
-
.setField('name', '')
|
|
105
|
-
.createAsync());
|
|
106
|
-
const entity2 = await RedisTestEntity_1.RedisTestEntity.loader(viewerContext).loadByFieldEqualingAsync('name', '');
|
|
107
|
-
(0, globals_1.expect)(entity2?.getID()).toEqual(entity1.getID());
|
|
108
|
-
// simulate new request
|
|
109
|
-
const vc2 = new TestViewerContext((0, createRedisIntegrationTestEntityCompanionProvider_1.createRedisIntegrationTestEntityCompanionProvider)(genericRedisCacheContext));
|
|
110
|
-
const entity3 = await RedisTestEntity_1.RedisTestEntity.loader(vc2).loadByFieldEqualingAsync('name', '');
|
|
111
|
-
(0, globals_1.expect)(entity3?.getID()).toEqual(entity1.getID());
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
//# sourceMappingURL=GenericRedisCacher-full-integration-test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GenericRedisCacher-full-integration-test.js","sourceRoot":"","sources":["../../../src/__integration-tests__/GenericRedisCacher-full-integration-test.ts"],"names":[],"mappings":";;;;;AAAA,yCAOsB;AACtB,2CAAmD;AACnD,2CAAsF;AACtF,sDAA4B;AAC5B,6BAA0B;AAC1B,+BAAoC;AAEpC,8DAI+B;AAC/B,yEAA6F;AAC7F,6IAA0I;AAE1I,MAAM,iBAAkB,SAAQ,sBAAa;CAAG;AAEhD,IAAA,kBAAQ,EAAC,uCAAkB,EAAE,GAAG,EAAE;IAChC,IAAI,wBAAkD,CAAC;IAEvD,IAAA,mBAAS,EAAC,GAAG,EAAE;QACb,wBAAwB,GAAG;YACzB,WAAW,EAAE,IAAI,iBAAK,CAAC,IAAI,SAAG,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;YACrE,SAAS,CAAC,GAAG,KAAe;gBAC1B,MAAM,SAAS,GAAG,GAAG,CAAC;gBACtB,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;gBACF,OAAO,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACtC,CAAC;YACD,cAAc,EAAE,OAAO;YACvB,kBAAkB,EAAE,KAAK,EAAE,QAAQ;YACnC,kBAAkB,EAAE,GAAG,EAAE,aAAa;YACtC,kBAAkB,EAAE;gBAClB,oBAAoB,EAAE,mDAA8B,CAAC,yBAAyB;aAC/E;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,IAAA,oBAAU,EAAC,KAAK,IAAI,EAAE;QACpB,MAAO,wBAAwB,CAAC,WAAqB,CAAC,OAAO,EAAE,CAAC;IAClE,CAAC,CAAC,CAAC;IACH,IAAA,kBAAQ,EAAC,KAA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M,CAAC,GAAG,CAAC,CAAC,wBAAwB,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACvF,IAAA,gBAAM,EAAC,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,93 +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 globals_1 = require("@jest/globals");
|
|
8
|
-
const ioredis_1 = __importDefault(require("ioredis"));
|
|
9
|
-
const url_1 = require("url");
|
|
10
|
-
const GenericRedisCacher_1 = require("../GenericRedisCacher");
|
|
11
|
-
const RedisTestEntity_1 = require("../__testfixtures__/RedisTestEntity");
|
|
12
|
-
const createRedisIntegrationTestEntityCompanionProvider_1 = require("../__testfixtures__/createRedisIntegrationTestEntityCompanionProvider");
|
|
13
|
-
class TestViewerContext extends entity_1.ViewerContext {
|
|
14
|
-
}
|
|
15
|
-
(0, globals_1.describe)(GenericRedisCacher_1.GenericRedisCacher, () => {
|
|
16
|
-
let genericRedisCacheContext;
|
|
17
|
-
(0, globals_1.beforeAll)(() => {
|
|
18
|
-
genericRedisCacheContext = {
|
|
19
|
-
redisClient: new ioredis_1.default(new url_1.URL(process.env['REDIS_URL']).toString()),
|
|
20
|
-
makeKeyFn(...parts) {
|
|
21
|
-
const delimiter = ':';
|
|
22
|
-
const escapedParts = parts.map((part) => part.replace('\\', '\\\\').replace(delimiter, `\\${delimiter}`));
|
|
23
|
-
return escapedParts.join(delimiter);
|
|
24
|
-
},
|
|
25
|
-
cacheKeyPrefix: 'test-',
|
|
26
|
-
ttlSecondsPositive: 86400, // 1 day
|
|
27
|
-
ttlSecondsNegative: 600, // 10 minutes
|
|
28
|
-
invalidationConfig: {
|
|
29
|
-
invalidationStrategy: GenericRedisCacher_1.RedisCacheInvalidationStrategy.CURRENT_CACHE_KEY_VERSION,
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
});
|
|
33
|
-
(0, globals_1.beforeEach)(async () => {
|
|
34
|
-
await genericRedisCacheContext.redisClient.flushdb();
|
|
35
|
-
});
|
|
36
|
-
(0, globals_1.afterAll)(async () => {
|
|
37
|
-
genericRedisCacheContext.redisClient.disconnect();
|
|
38
|
-
});
|
|
39
|
-
(0, globals_1.it)('has correct caching and loading behavior', async () => {
|
|
40
|
-
const viewerContext = new TestViewerContext((0, createRedisIntegrationTestEntityCompanionProvider_1.createRedisIntegrationTestEntityCompanionProvider)(genericRedisCacheContext));
|
|
41
|
-
const genericRedisCacher = new GenericRedisCacher_1.GenericRedisCacher(genericRedisCacheContext, RedisTestEntity_1.redisTestEntityConfiguration);
|
|
42
|
-
const date = new Date();
|
|
43
|
-
const entity1Created = await RedisTestEntity_1.RedisTestEntity.creator(viewerContext)
|
|
44
|
-
.setField('name', 'blah')
|
|
45
|
-
.setField('dateField', date)
|
|
46
|
-
.createAsync();
|
|
47
|
-
const testKey = `test-id-key-${entity1Created.getID()}`;
|
|
48
|
-
const objectMap = new Map([
|
|
49
|
-
[testKey, entity1Created.getAllFields()],
|
|
50
|
-
]);
|
|
51
|
-
await genericRedisCacher.cacheManyAsync(objectMap);
|
|
52
|
-
const cachedJSON = await genericRedisCacheContext.redisClient.get(testKey);
|
|
53
|
-
const cachedValue = JSON.parse(cachedJSON);
|
|
54
|
-
(0, globals_1.expect)(cachedValue).toMatchObject({
|
|
55
|
-
id: entity1Created.getID(),
|
|
56
|
-
dateField: date.toISOString(),
|
|
57
|
-
});
|
|
58
|
-
const loadedObjectMap = await genericRedisCacher.loadManyAsync([testKey]);
|
|
59
|
-
const cacheLoadResult = loadedObjectMap.get(testKey);
|
|
60
|
-
(0, globals_1.expect)(cacheLoadResult).toMatchObject({
|
|
61
|
-
status: entity_1.CacheStatus.HIT,
|
|
62
|
-
item: entity1Created.getAllFields(),
|
|
63
|
-
});
|
|
64
|
-
(0, globals_1.expect)(loadedObjectMap.size).toBe(1);
|
|
65
|
-
});
|
|
66
|
-
(0, globals_1.it)('has correct negative caching behaviour', async () => {
|
|
67
|
-
const genericRedisCacher = new GenericRedisCacher_1.GenericRedisCacher(genericRedisCacheContext, RedisTestEntity_1.redisTestEntityConfiguration);
|
|
68
|
-
const testKey = `test-id-key-non-existent-id`;
|
|
69
|
-
await genericRedisCacher.cacheDBMissesAsync([testKey]);
|
|
70
|
-
const loadedObjectMap = await genericRedisCacher.loadManyAsync([testKey]);
|
|
71
|
-
const cacheLoadResult = loadedObjectMap.get(testKey);
|
|
72
|
-
(0, globals_1.expect)(cacheLoadResult.status).toBe(entity_1.CacheStatus.NEGATIVE);
|
|
73
|
-
});
|
|
74
|
-
(0, globals_1.it)('has correct invalidation behaviour', async () => {
|
|
75
|
-
const viewerContext = new TestViewerContext((0, createRedisIntegrationTestEntityCompanionProvider_1.createRedisIntegrationTestEntityCompanionProvider)(genericRedisCacheContext));
|
|
76
|
-
const genericRedisCacher = new GenericRedisCacher_1.GenericRedisCacher(genericRedisCacheContext, RedisTestEntity_1.redisTestEntityConfiguration);
|
|
77
|
-
const date = new Date();
|
|
78
|
-
const entity1Created = await RedisTestEntity_1.RedisTestEntity.creator(viewerContext)
|
|
79
|
-
.setField('name', 'blah')
|
|
80
|
-
.setField('dateField', date)
|
|
81
|
-
.createAsync();
|
|
82
|
-
const testKey = `test-id-key-${entity1Created.getID()}`;
|
|
83
|
-
const objectMap = new Map([
|
|
84
|
-
[testKey, entity1Created.getAllFields()],
|
|
85
|
-
]);
|
|
86
|
-
await genericRedisCacher.cacheManyAsync(objectMap);
|
|
87
|
-
await genericRedisCacher.invalidateManyAsync([testKey]);
|
|
88
|
-
const loadedObjectMap = await genericRedisCacher.loadManyAsync([testKey]);
|
|
89
|
-
const cacheLoadResult = loadedObjectMap.get(testKey);
|
|
90
|
-
(0, globals_1.expect)(cacheLoadResult.status).toBe(entity_1.CacheStatus.MISS);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
//# sourceMappingURL=GenericRedisCacher-integration-test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GenericRedisCacher-integration-test.js","sourceRoot":"","sources":["../../../src/__integration-tests__/GenericRedisCacher-integration-test.ts"],"names":[],"mappings":";;;;;AAAA,yCAA0D;AAC1D,2CAAsF;AACtF,sDAA4B;AAC5B,6BAA0B;AAE1B,8DAI+B;AAC/B,yEAI6C;AAC7C,6IAA0I;AAE1I,MAAM,iBAAkB,SAAQ,sBAAa;CAAG;AAEhD,IAAA,kBAAQ,EAAC,uCAAkB,EAAE,GAAG,EAAE;IAChC,IAAI,wBAAkD,CAAC;IAEvD,IAAA,mBAAS,EAAC,GAAG,EAAE;QACb,wBAAwB,GAAG;YACzB,WAAW,EAAE,IAAI,iBAAK,CAAC,IAAI,SAAG,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;YACrE,SAAS,CAAC,GAAG,KAAe;gBAC1B,MAAM,SAAS,GAAG,GAAG,CAAC;gBACtB,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;gBACF,OAAO,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACtC,CAAC;YACD,cAAc,EAAE,OAAO;YACvB,kBAAkB,EAAE,KAAK,EAAE,QAAQ;YACnC,kBAAkB,EAAE,GAAG,EAAE,aAAa;YACtC,kBAAkB,EA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