@envelop/response-cache-redis 4.3.1 → 4.4.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/LICENSE +3 -1
- package/cjs/redis-cache.js +7 -9
- package/esm/redis-cache.js +7 -9
- package/package.json +4 -4
- package/typings/redis-cache.d.cts +1 -1
- package/typings/redis-cache.d.ts +1 -1
package/LICENSE
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2020
|
|
3
|
+
Copyright (c) 2018-2020 Graphcool
|
|
4
|
+
Copyright (c) 2020-2021 Prisma
|
|
5
|
+
Copyright (c) 2021- The Guild
|
|
4
6
|
|
|
5
7
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
8
|
of this software and associated documentation files (the "Software"), to deal
|
package/cjs/redis-cache.js
CHANGED
|
@@ -11,10 +11,9 @@ const createRedisCache = (params) => {
|
|
|
11
11
|
// find the responseIds for the entity
|
|
12
12
|
const responseIds = await store.smembers(entity);
|
|
13
13
|
// and add each response to be invalidated since they contained the entity data
|
|
14
|
-
|
|
15
|
-
keysToInvalidate.push(responseId);
|
|
16
|
-
|
|
17
|
-
});
|
|
14
|
+
for (const responseId of responseIds) {
|
|
15
|
+
keysToInvalidate.push(responseId, buildRedisOperationResultCacheKey(responseId));
|
|
16
|
+
}
|
|
18
17
|
// if invalidating an entity like Comment, then also invalidate Comment:1, Comment:2, etc
|
|
19
18
|
if (!entity.includes(':')) {
|
|
20
19
|
const entityKeys = await store.keys(`${entity}:*`);
|
|
@@ -23,10 +22,9 @@ const createRedisCache = (params) => {
|
|
|
23
22
|
const entityResponseIds = await store.smembers(entityKey);
|
|
24
23
|
// if invalidating an entity check for associated operations containing that entity
|
|
25
24
|
// and invalidate each response since they contained the entity data
|
|
26
|
-
|
|
27
|
-
keysToInvalidate.push(responseId);
|
|
28
|
-
|
|
29
|
-
});
|
|
25
|
+
for (const responseId of entityResponseIds) {
|
|
26
|
+
keysToInvalidate.push(responseId, buildRedisOperationResultCacheKey(responseId));
|
|
27
|
+
}
|
|
30
28
|
// then the entityKeys like Comment:1, Comment:2 etc to be invalidated
|
|
31
29
|
keysToInvalidate.push(entityKey);
|
|
32
30
|
}
|
|
@@ -65,7 +63,7 @@ const createRedisCache = (params) => {
|
|
|
65
63
|
async invalidate(entitiesToRemove) {
|
|
66
64
|
const invalidationKeys = [];
|
|
67
65
|
for (const { typename, id } of entitiesToRemove) {
|
|
68
|
-
invalidationKeys.push(await buildEntityInvalidationsKeys(id
|
|
66
|
+
invalidationKeys.push(await buildEntityInvalidationsKeys(id == null ? typename : buildRedisEntityId(typename, id)));
|
|
69
67
|
}
|
|
70
68
|
const keys = invalidationKeys.flat();
|
|
71
69
|
if (keys.length > 0) {
|
package/esm/redis-cache.js
CHANGED
|
@@ -8,10 +8,9 @@ export const createRedisCache = (params) => {
|
|
|
8
8
|
// find the responseIds for the entity
|
|
9
9
|
const responseIds = await store.smembers(entity);
|
|
10
10
|
// and add each response to be invalidated since they contained the entity data
|
|
11
|
-
|
|
12
|
-
keysToInvalidate.push(responseId);
|
|
13
|
-
|
|
14
|
-
});
|
|
11
|
+
for (const responseId of responseIds) {
|
|
12
|
+
keysToInvalidate.push(responseId, buildRedisOperationResultCacheKey(responseId));
|
|
13
|
+
}
|
|
15
14
|
// if invalidating an entity like Comment, then also invalidate Comment:1, Comment:2, etc
|
|
16
15
|
if (!entity.includes(':')) {
|
|
17
16
|
const entityKeys = await store.keys(`${entity}:*`);
|
|
@@ -20,10 +19,9 @@ export const createRedisCache = (params) => {
|
|
|
20
19
|
const entityResponseIds = await store.smembers(entityKey);
|
|
21
20
|
// if invalidating an entity check for associated operations containing that entity
|
|
22
21
|
// and invalidate each response since they contained the entity data
|
|
23
|
-
|
|
24
|
-
keysToInvalidate.push(responseId);
|
|
25
|
-
|
|
26
|
-
});
|
|
22
|
+
for (const responseId of entityResponseIds) {
|
|
23
|
+
keysToInvalidate.push(responseId, buildRedisOperationResultCacheKey(responseId));
|
|
24
|
+
}
|
|
27
25
|
// then the entityKeys like Comment:1, Comment:2 etc to be invalidated
|
|
28
26
|
keysToInvalidate.push(entityKey);
|
|
29
27
|
}
|
|
@@ -62,7 +60,7 @@ export const createRedisCache = (params) => {
|
|
|
62
60
|
async invalidate(entitiesToRemove) {
|
|
63
61
|
const invalidationKeys = [];
|
|
64
62
|
for (const { typename, id } of entitiesToRemove) {
|
|
65
|
-
invalidationKeys.push(await buildEntityInvalidationsKeys(id
|
|
63
|
+
invalidationKeys.push(await buildEntityInvalidationsKeys(id == null ? typename : buildRedisEntityId(typename, id)));
|
|
66
64
|
}
|
|
67
65
|
const keys = invalidationKeys.flat();
|
|
68
66
|
if (keys.length > 0) {
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/response-cache-redis",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@whatwg-node/promise-helpers": "^1.2.4",
|
|
7
7
|
"ioredis": "^5.4.2",
|
|
8
8
|
"tslib": "^2.5.0",
|
|
9
|
-
"@envelop/response-cache": "^9.
|
|
9
|
+
"@envelop/response-cache": "^9.2.0"
|
|
10
10
|
},
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "https://github.com/graphql-hive/
|
|
14
|
-
"directory": "packages/plugins/response-cache-redis"
|
|
13
|
+
"url": "https://github.com/graphql-hive/graphql-yoga.git",
|
|
14
|
+
"directory": "packages/envelop/plugins/response-cache-redis"
|
|
15
15
|
},
|
|
16
16
|
"author": "David Thyresson <dthyresson@gmail.com>",
|
|
17
17
|
"license": "MIT",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Redis from 'ioredis';
|
|
1
|
+
import type Redis from 'ioredis';
|
|
2
2
|
import type { Cache } from '@envelop/response-cache';
|
|
3
3
|
export type BuildRedisEntityId = (typename: string, id: number | string) => string;
|
|
4
4
|
export type BuildRedisOperationResultCacheKey = (responseId: string) => string;
|
package/typings/redis-cache.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Redis from 'ioredis';
|
|
1
|
+
import type Redis from 'ioredis';
|
|
2
2
|
import type { Cache } from '@envelop/response-cache';
|
|
3
3
|
export type BuildRedisEntityId = (typename: string, id: number | string) => string;
|
|
4
4
|
export type BuildRedisOperationResultCacheKey = (responseId: string) => string;
|