cache-manager icon indicating copy to clipboard operation
cache-manager copied to clipboard

Support of `[email protected]` ?

Open xavierraffin opened this issue 1 year ago • 4 comments

Is there an existing issue that is already proposing this?

  • [X] I have searched the existing issues

Is your feature request related to a problem? Please describe it

cache-manager 6 has been released (6.1.0 as of today). But the installation of it with @nestjs/[email protected] gives warning on potential compatibility issues:

npm warn ERESOLVE overriding peer dependency
npm warn Found: [email protected]
npm warn node_modules/cache-manager
npm warn   peer cache-manager@"<=5" from @nestjs/[email protected]
npm warn   node_modules/@nestjs/cache-manager
npm warn     @nestjs/cache-manager@"^2.2.2" from the root project
npm warn   1 more (the root project)
npm warn
npm warn Could not resolve dependency:
npm warn peer cache-manager@"<=5" from @nestjs/[email protected]
npm warn node_modules/@nestjs/cache-manager
npm warn   @nestjs/cache-manager@"^2.2.2" from the root project

Indeed, cache-manager 6 switched from cache-manager-ioredis-yet to keyv (because of being "more actively maintained and have a larger community" as the npm cache manager page says.). This may require some code update (it did inside my code), or at least on the examples.

Describe the solution you'd like

A new release of @nestjs/cache-manager which supports the cache-manager 6 package.

If that could help, here is the cache interface I needed to create to make it work on v6:

import { CacheStore } from "@nestjs/common/cache/interfaces/cache-manager.interface";
import Keyv from "keyv";

export class KeyvStore implements CacheStore {
  private keyv: Keyv<any>;

  constructor(keyv: Keyv<any>) {
    this.keyv = keyv;
  }

  async get<T>(key: string): Promise<T | undefined> {
    return this.keyv.get(key);
  }

  async set<T>(key: string, value: T, ttl?: number): Promise<void> {
    await this.keyv.set(key, value, ttl);
  }

  async del(key: string): Promise<void> {
    await this.keyv.delete(key);
  }

  async reset(): Promise<void> {
    await this.keyv.clear();
  }
}

Maybe something you like to add in @nestjs/cache-manager ?

Teachability, documentation, adoption, migration strategy

No response

What is the motivation / use case for changing the behavior?

No behavior changes

xavierraffin avatar Oct 08 '24 18:10 xavierraffin

It seems that there is a PR: https://github.com/nestjs/cache-manager/pull/501 (from this Apr 2023 ticket??? https://github.com/nestjs/cache-manager/issues/3)

But that will be nicer to get a Cache Store as well

xavierraffin avatar Oct 08 '24 18:10 xavierraffin

PR on this: https://github.com/nestjs/cache-manager/pull/508

xavierraffin avatar Oct 08 '24 18:10 xavierraffin

yes, same issue

ArcherGu avatar Oct 10 '24 00:10 ArcherGu

+1

mghizzo avatar Oct 10 '24 18:10 mghizzo

same here apps/backend/src/app/api/app.module.ts:50:7 - error TS2322: Type '() => Promise<{ store: RedisStore; }>' is not assignable to type '(...args: any[]) => CacheOptions<{ store: RedisStore; }> | Promise<CacheOptions<{ store: RedisStore; }>>'

was using cache-manager-ioredis-yet

nodegin avatar Oct 11 '24 18:10 nodegin

Adding this here as there is working being done to move to cache-manager v6: https://github.com/nestjs/cache-manager/pull/508

jaredwray avatar Oct 16 '24 15:10 jaredwray

Let's track this here https://github.com/nestjs/cache-manager/pull/508

We're going to support v6 in the next major release

kamilmysliwiec avatar Oct 18 '24 12:10 kamilmysliwiec

Pls, add a remark to docs, that NestJS doesn't currently support cache-manager@6.

bluin4308 avatar Nov 06 '24 14:11 bluin4308

Pls, add a remark to docs, that NestJS doesn't currently support cache-manager@6.

Just to support this, you get this error message when using cache-manager@6 cacheManager.caching is not a function

The-True-Hooha avatar Nov 12 '24 13:11 The-True-Hooha