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

upgrade lru-cache to 10 #3

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@nestjs/common": "^10",
"@nestjs/core": "^10",
"@nestjs/graphql": "^12",
"lru-cache": "^6",
"lru-cache": "^10",
"protobufjs": "^7.1.2",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1"
Expand All @@ -61,7 +61,6 @@
"@nestjs/testing": "^10.3.3",
"@types/express": "^4.17.21",
"@types/jest": "^29.5.12",
"@types/lru-cache": "^7.10.10",
"@types/node": "^20",
"@types/supertest": "^2.0.12",
"@typescript-eslint/eslint-plugin": "^7.1.0",
Expand All @@ -76,7 +75,7 @@
"graphql": "^16.8.1",
"jest": "^29.3.1",
"jest-extended": "^3.2.1",
"lru-cache": "^7.14.1",
"lru-cache": "^10.2.0",
"npm-run-all": "^4.1.5",
"prettier": "^3.2.5",
"protobufjs": "^7.1.2",
Expand Down
6 changes: 3 additions & 3 deletions src/dataloaders/grpc-dataloader.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import DataLoader from 'dataloader';
import { Observable } from 'rxjs';
import { GrpcDataLoaderProvider } from './grpc-dataloader.provider';
import { getRequest, Request } from '../utils';
import LRU from 'lru-cache';
import { LRUCache } from 'lru-cache';

@Injectable()
export class GrpcDataLoaderInterceptor implements NestInterceptor {
private readonly logger = new Logger(GrpcDataLoaderInterceptor.name);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
private lru: LRU<string, any>;
private lru: LRUCache<string, any>;

constructor(private moduleRef: ModuleRef) {
this.lru = new LRU({
this.lru = new LRUCache({
max: 500,
ttl: 1000,
});
Expand Down
6 changes: 3 additions & 3 deletions src/dataloaders/grpc-dataloader.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { UncachedDataloader } from './uncached.dataloader';
import { FirstArgumentType, ReturnType } from '../types/util.types';
import { Request } from '../utils';
import { catchError } from 'rxjs/operators';
import LRU from 'lru-cache';
import { LRUCache } from 'lru-cache';

interface CacheSingleConfig<M> {
cacheKeyFn: (request: FirstArgumentType<M>) => string;
Expand All @@ -33,7 +33,7 @@ export type MergeConfig<Client> = Partial<{
}>;

function wrapCache<K, V>(
cache: LRU<string, Promise<V>>,
cache: LRUCache<string, Promise<V>>,
config: CacheSingleConfig<(req: K) => Observable<V>>
): CacheMap<string, Promise<V>> {
return {
Expand All @@ -60,7 +60,7 @@ export abstract class GrpcDataLoaderProvider<Client extends object> {
generateDataLoader<ID, Type>(
methodName: string,
request: Request,
cache?: LRU<string, Promise<Type>>
cache?: LRUCache<string, Promise<Type>>
): DataLoader<ID, Type> {
this.logger.debug(
`Creating dataloader ${methodName} in ${this.constructor.name}`
Expand Down
14 changes: 1 addition & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1431,13 +1431,6 @@
resolved "https://registry.npmjs.org/@types/long/-/long-4.0.2.tgz#b74129719fc8d11c01868010082d483b7545591a"
integrity sha512-MqTGEo5bj5t157U6fA/BiDynNkn0YknVdh48CMPkTSpFTVmvao5UQmm7uEF6xBEo7qIMAlY/JSleYaE6VOdpaA==

"@types/lru-cache@^7.10.10":
version "7.10.10"
resolved "https://registry.npmjs.org/@types/lru-cache/-/lru-cache-7.10.10.tgz#3fa937c35ff4b3f6753d5737915c9bf8e693a713"
integrity sha512-nEpVRPWW9EBmx2SCfNn3ClYxPL7IktPX12HhIoSc/H5mMjdeW3+YsXIpseLQ2xF35+OcpwKQbEUw5VtqE4PDNA==
dependencies:
lru-cache "*"

"@types/mime@^1":
version "1.3.2"
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.2.tgz#93e25bf9ee75fe0fd80b594bc4feb0e862111b5a"
Expand Down Expand Up @@ -4552,17 +4545,12 @@ long@^5.0.0:
resolved "https://registry.npmjs.org/long/-/long-5.2.1.tgz#e27595d0083d103d2fa2c20c7699f8e0c92b897f"
integrity sha512-GKSNGeNAtw8IryjjkhZxuKB3JzlcLTwjtiQCHKvqQet81I93kXslhDQruGI/QsddO83mcDToBVy7GqGS/zYf/A==

lru-cache@*, lru-cache@^7.14.1:
version "7.14.1"
resolved "https://registry.npmjs.org/lru-cache/-/lru-cache-7.14.1.tgz#8da8d2f5f59827edb388e63e459ac23d6d408fea"
integrity sha512-ysxwsnTKdAx96aTRdhDOCQfDgbHnt8SK0KY8SEjO0wHinhWOFTESbjVCMPbU1uGXg/ch4lifqx0wfjOawU2+WA==

"[email protected] - 7.13.1":
version "7.13.1"
resolved "https://registry.npmjs.org/lru-cache/-/lru-cache-7.13.1.tgz#267a81fbd0881327c46a81c5922606a2cfe336c4"
integrity sha512-CHqbAq7NFlW3RSnoWXLJBxCWaZVBrfa9UEHId2M3AW8iEBurbqduNexEUCGc3SHc6iCYXNJCDi903LajSVAEPQ==

lru-cache@^10.1.0, "lru-cache@^9.1.1 || ^10.0.0":
lru-cache@^10.1.0, lru-cache@^10.2.0, "lru-cache@^9.1.1 || ^10.0.0":
version "10.2.0"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.2.0.tgz#0bd445ca57363465900f4d1f9bd8db343a4d95c3"
integrity sha512-2bIM8x+VAf6JT4bKAljS1qUWgMsqZRPGJS6FSahIMPVvctcNhyVp7AJu7quxOW9jwkryBReKZY5tY5JYv2n/7Q==
Expand Down
Loading