Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(common): fix cache ttl not beeing respected #11131

Merged
merged 5 commits into from
Mar 15, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions packages/common/cache/interceptors/cache.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ import {
const HTTP_ADAPTER_HOST = 'HttpAdapterHost';
const REFLECTOR = 'Reflector';

// We need to check if the cache-manager package is v5 or greater
// because the set method signature changed in v5
const cacheManager = loadPackage('cache-manager', 'CacheModule', () =>
require('cache-manager'),
);
const cacheManagerIsv5OrGreater = 'memoryStore' in cacheManager;

export interface HttpAdapterHost<T extends HttpServer = any> {
httpAdapter: T;
}
Expand Down Expand Up @@ -67,6 +60,14 @@ export class CacheInterceptor implements NestInterceptor {
const ttl = isFunction(ttlValueOrFactory)
? await ttlValueOrFactory(context)
: ttlValueOrFactory;

// We need to check if the cache-manager package is v5 or greater
// because the set method signature changed in v5
const cacheManager = loadPackage('cache-manager', 'CacheModule', () =>
require('cache-manager'),
);
const cacheManagerIsv5OrGreater = 'memoryStore' in cacheManager;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will be called everytime we intercept something, which isn't needed as this won't change over time.

What about moving such logic to constructor instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, ye good catch. My bad :)


return next.handle().pipe(
tap(async response => {
if (response instanceof StreamableFile) {
Expand Down