Skip to content

Commit

Permalink
feat(platform-cache): add cache.ignoreHeaders option to exclude heade…
Browse files Browse the repository at this point in the history
…r when caching the response
  • Loading branch information
Romakita committed Mar 11, 2024
1 parent 965a61b commit 9768539
Show file tree
Hide file tree
Showing 64 changed files with 85 additions and 103 deletions.
5 changes: 2 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,5 @@
"barrelsby": "^2.8.1",
"eslint": "^8.12.0",
"jest": "^29.2.0"
},
"peerDependencies": {}
}
}
}
2 changes: 1 addition & 1 deletion packages/di/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@
"optional": false
}
}
}
}
5 changes: 2 additions & 3 deletions packages/engines/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,5 @@
"decorators",
"engines",
"view"
],
"peerDependencies": {}
}
]
}
2 changes: 1 addition & 1 deletion packages/graphql/apollo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@
"apollo-server-core": ">=3.0.0",
"graphql": ">15.0.0"
}
}
}
2 changes: 1 addition & 1 deletion packages/graphql/graphql-ws/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@
"@tsed/logger": ">=6.2.2",
"graphql-ws": ">=5.14.2"
}
}
}
2 changes: 1 addition & 1 deletion packages/graphql/typegraphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
"graphql": ">=15.0.0",
"type-graphql": ">=1.0.0"
}
}
}
2 changes: 1 addition & 1 deletion packages/orm/adapters-redis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
"ioredis-mock": ">=8.2.2",
"uuid": "8.3.2"
}
}
}
2 changes: 1 addition & 1 deletion packages/orm/adapters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@
"optional": false
}
}
}
}
2 changes: 1 addition & 1 deletion packages/orm/ioredis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@
"ioredis": ">=5.2.3",
"ioredis-mock": ">=8.2.2"
}
}
}
2 changes: 1 addition & 1 deletion packages/orm/mikro-orm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@
"@tsed/di": "7.62.3",
"@tsed/logger": ">=6.2.2"
}
}
}
2 changes: 1 addition & 1 deletion packages/orm/mongoose/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@
"@tsed/schema": "7.62.3",
"mongoose": ">=6.0.0"
}
}
}
2 changes: 1 addition & 1 deletion packages/orm/objection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@
"optional": false
}
}
}
}
2 changes: 1 addition & 1 deletion packages/orm/prisma/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@
"tsed",
"prisma"
]
}
}
2 changes: 1 addition & 1 deletion packages/orm/testing-mongoose/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
"@tsed/mongoose": "7.62.3",
"mongoose": ">=6.0.0"
}
}
}
2 changes: 1 addition & 1 deletion packages/orm/typeorm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@
"publishConfig": {
"distTag": "deprecated"
}
}
}
5 changes: 2 additions & 3 deletions packages/perf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@
"@tsed/typescript": "workspace:*",
"eslint": "^8.12.0",
"jest": "^29.2.0"
},
"peerDependencies": {}
}
}
}
2 changes: 1 addition & 1 deletion packages/platform/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@
"optional": false
}
}
}
}
2 changes: 1 addition & 1 deletion packages/platform/platform-cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@
"optional": false
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import {PlatformCacheOptions} from "../interfaces/PlatformCacheOptions";
import {PlatformCache} from "../services/PlatformCache";
import {getPrefix} from "../utils/getPrefix";
import {isEndpoint} from "../utils/isEndpoint";

const cleanHeaders = (headers: Record<string, unknown>) => {
const cleanHeaders = (headers: Record<string, unknown>, blacklist: string[]) => {
return Object.entries(headers)
.filter(([key]) => !["content-length", "x-request-id", "cache-control"].includes(key))
.filter(([key]) => !blacklist.includes(key.toLowerCase()))
.reduce((headers, [key, value]) => {
return {
...headers,
Expand All @@ -34,6 +33,9 @@ export class PlatformCacheInterceptor implements InterceptorMethods {
@Constant("cache.prefix", "")
protected prefix: string;

@Constant("cache.ignoreHeaders", ["content-length", "x-request-id", "cache-control", "vary", "content-encoding"])
protected blacklist: string[];

intercept(context: InterceptorContext<any, PlatformCacheOptions>, next: InterceptorNext) {
if (this.cache.disabled()) {
return next();
Expand Down Expand Up @@ -145,7 +147,7 @@ export class PlatformCacheInterceptor implements InterceptorMethods {
this.cache.setCachedObject(key, response.getBody(), {
ttl: calculatedTTL,
args,
headers: cleanHeaders(response.getHeaders())
headers: cleanHeaders(response.getHeaders(), this.blacklist)
});
});

Expand Down
4 changes: 4 additions & 0 deletions packages/platform/platform-cache/src/interfaces/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export type PlatformCacheSettings<Config extends object = any, S extends Store =
max?: number;
keyResolver?: (args: any[], ctx: BaseContext) => string;
prefix?: string;
/**
* List of headers to ignore when caching the response. Default: ["content-length", "x-request-id", "cache-control", "vary", "content-encoding"]
*/
ignoreHeaders?: string[];
/**
* You may pass in any other arguments these will be passed on to the `create` method of your store,
* otherwise they will be ignored.
Expand Down
2 changes: 1 addition & 1 deletion packages/platform/platform-exceptions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@
"optional": false
}
}
}
}
2 changes: 1 addition & 1 deletion packages/platform/platform-express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,4 @@
"optional": false
}
}
}
}
2 changes: 1 addition & 1 deletion packages/platform/platform-koa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,4 @@
"optional": false
}
}
}
}
2 changes: 1 addition & 1 deletion packages/platform/platform-log-middleware/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@
"optional": false
}
}
}
}
2 changes: 1 addition & 1 deletion packages/platform/platform-middlewares/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@
"optional": true
}
}
}
}
2 changes: 1 addition & 1 deletion packages/platform/platform-params/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@
"optional": false
}
}
}
}
2 changes: 1 addition & 1 deletion packages/platform/platform-response-filter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@
"optional": false
}
}
}
}
2 changes: 1 addition & 1 deletion packages/platform/platform-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@
"optional": false
}
}
}
}
2 changes: 1 addition & 1 deletion packages/platform/platform-serverless-http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@
"optional": false
}
}
}
}
2 changes: 1 addition & 1 deletion packages/platform/platform-serverless-testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@
"@tsed/openspec": "7.62.3",
"@tsed/schema": "7.62.3"
}
}
}
2 changes: 1 addition & 1 deletion packages/platform/platform-serverless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@
"optional": true
}
}
}
}
5 changes: 2 additions & 3 deletions packages/platform/platform-test-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,5 @@
"barrelsby": "^2.8.1",
"eslint": "^8.12.0",
"jest": "^29.2.0"
},
"peerDependencies": {}
}
}
}
2 changes: 1 addition & 1 deletion packages/platform/platform-views/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@
"optional": false
}
}
}
}
5 changes: 2 additions & 3 deletions packages/security/jwks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,5 @@
"barrelsby": "^2.8.1",
"eslint": "^8.12.0",
"jest": "^29.2.0"
},
"peerDependencies": {}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@
"optional": false
}
}
}
}
2 changes: 1 addition & 1 deletion packages/security/oidc-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@
"optional": false
}
}
}
}
2 changes: 1 addition & 1 deletion packages/security/passport/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@
"optional": false
}
}
}
}
2 changes: 1 addition & 1 deletion packages/specs/ajv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@
"optional": false
}
}
}
}
2 changes: 1 addition & 1 deletion packages/specs/exceptions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
"peerDependencies": {
"@tsed/core": "7.62.3"
}
}
}
2 changes: 1 addition & 1 deletion packages/specs/json-mapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@
"optional": false
}
}
}
}
6 changes: 2 additions & 4 deletions packages/specs/openspec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,5 @@
"barrelsby": "^2.8.1",
"eslint": "^8.12.0",
"jest": "^29.2.0"
},
"dependencies": {},
"peerDependencies": {}
}
}
}
2 changes: 1 addition & 1 deletion packages/specs/schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@
"optional": false
}
}
}
}
2 changes: 1 addition & 1 deletion packages/specs/swagger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@
"optional": false
}
}
}
}
2 changes: 1 addition & 1 deletion packages/third-parties/agenda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
"peerDependencies": {
"agenda": ">=4"
}
}
}
2 changes: 1 addition & 1 deletion packages/third-parties/bullmq/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@
"peerDependencies": {
"bullmq": "^4.12.3 || ^5.1.1"
}
}
}
2 changes: 1 addition & 1 deletion packages/third-parties/components-scan/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
"optional": false
}
}
}
}
2 changes: 1 addition & 1 deletion packages/third-parties/event-emitter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@
"peerDependencies": {
"eventemitter2": "^6.4.4"
}
}
}
2 changes: 1 addition & 1 deletion packages/third-parties/formio-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@
"eslint": "^8.12.0",
"jest": "^29.2.0"
}
}
}
2 changes: 1 addition & 1 deletion packages/third-parties/formio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@
"optional": false
}
}
}
}
2 changes: 1 addition & 1 deletion packages/third-parties/schema-formio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@
"optional": false
}
}
}
}

0 comments on commit 9768539

Please sign in to comment.