jaredwray / cache-manager

Cache module for Node.JS
MIT License
1.4k stars 152 forks source link

Value being set inside "v" field on new version v2 #669

Closed RabahZeineddine closed 2 months ago

RabahZeineddine commented 2 months ago

Describe the bug

After updating the lib to the new v2 version every value is being set inside a v field

How To Reproduce (best to provide workable code or tests!) Check my implementation


import { Cache, caching } from 'cache-manager';
import { RedisStore, redisStore } from 'cache-manager-ioredis-yet';

export class MyClass {

  store: RedisStore;
  private cacheManager: Cache<RedisStore>;

    private async getCacheManager() {
    if (this.cacheManager) return;

    this.store = await redisStore({
      host: this.options.redis.host,
      db: this.options.redis.db,
      ttl: this.options.redis.defaultTTL,
    });
    this.cacheManager = await caching(this.store);
  }

  async cacheGet<T>(key: string): Promise<T | undefined> {
    await this.getCacheManager();
    return this.cacheManager.get<T>(key);
  }

  async cacheSet(key: string, value: unknown, ttl?: number): Promise<void> {
    if (!ttl) ttl = this.options.redis.defaultTTL ?? 0;
    await this.getCacheManager();
    return this.cacheManager.set(key, value, ttl);
  }
}

After using the cacheSet and cacheGet method, I'm getting this results. Captura de Tela 2024-04-28 às 16 13 36

I'm setting a normal number (not an object)

jaredwray commented 2 months ago

@RabahZeineddine - thanks for creating this bug and we will be looking into this soon.

jaredwray commented 2 months ago

@RabahZeineddine - this will be deployed in a couple weeks.