npm cache-manager 'wrap' doesn't exist

217 Views Asked by At

I inherited an app with nest js and am now working on updating it, as it is a few years old. I am experiencing problems in particular with the npm package "cache-manager," which is being updated from version "3.6.1" to "5.2.4."

After declaring in the caching/index.ts file:

import * as cacheManager from "cache-manager";

export const rootDataCacheTtl = () =>
  process.env.NODE_ENV === "development" ? 0 : 5 * 60


export const rootDataCache = cacheManager.caching( 'memory',  {
  max:100,
  ttl: rootDataCacheTtl(),
})

This is a change I implemented, since in the previous version, the implementation was:

export const rootDataCache = cacheManager.caching({
  store: "memory",
  ttl: rootDataCacheTtl(),
})

Now, when I go to use the wrap property in my controller, I get the error that "Property 'wrap' does not exist on type 'Promise <MemoryCache'":

  async appRootContents(
    @Query("language") language: string
  ): Promise<AppRootData> {
    return await rootDataCache.wrap(`appRootContents-${language}`, () => {
      return fetchAppRootData(language)
    }
    )
  }

I apologize in advance if the configuration is a bit confusing, precisely I am trying to update this app and I am not familiar with the package.

0

There are 0 best solutions below