@envelop/response-cache-redis 4.3.1 → 4.5.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 CHANGED
@@ -1,6 +1,8 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 Dotan Simha
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
@@ -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
- responseIds.forEach(responseId => {
15
- keysToInvalidate.push(responseId);
16
- keysToInvalidate.push(buildRedisOperationResultCacheKey(responseId));
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
- entityResponseIds.forEach(responseId => {
27
- keysToInvalidate.push(responseId);
28
- keysToInvalidate.push(buildRedisOperationResultCacheKey(responseId));
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 != null ? buildRedisEntityId(typename, id) : typename));
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) {
@@ -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
- responseIds.forEach(responseId => {
12
- keysToInvalidate.push(responseId);
13
- keysToInvalidate.push(buildRedisOperationResultCacheKey(responseId));
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
- entityResponseIds.forEach(responseId => {
24
- keysToInvalidate.push(responseId);
25
- keysToInvalidate.push(buildRedisOperationResultCacheKey(responseId));
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 != null ? buildRedisEntityId(typename, id) : typename));
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.1",
3
+ "version": "4.5.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.1.1"
9
+ "@envelop/response-cache": "^9.3.0"
10
10
  },
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "https://github.com/graphql-hive/envelop.git",
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;
@@ -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;