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

[Bug] store.get is not a function

Open rivaslive opened this issue 2 years ago • 11 comments

This error is happend

const cacheCollectionSQLiteStore = cacheManager.caching({
  store: sqliteStore,
  options: {
    serializer: 'json',
    ttl: ONE_MINUTE * 60
  }
});


async function getCollectionsInfoFromCache() {
  const cacheStore = await cacheCollectionStore;

  // Launch error
  const dataCache = await cacheStore.get('foo');
}

Error image

image

Node 16.x Strapi v4

rivaslive avatar Feb 18 '23 06:02 rivaslive

I think your problem is

const cacheStore = await cacheCollectionStore;

You don't that line, and I wonder where did you get that line from?

maxpert avatar Feb 20 '23 22:02 maxpert

This error is happend


const cacheCollectionSQLiteStore = cacheManager.caching({

  store: sqliteStore,

  options: {

    serializer: 'json',

    ttl: ONE_MINUTE * 60

  }

});





async function getCollectionsInfoFromCache() {

  const cacheStore = await cacheCollectionStore;



  // Launch error

  const dataCache = await cacheStore.get('foo');

}

Error image

image

Node 16.x

Strapi v4

I have the same issue using the package.

Please does anyone have a solution?. I'm using nestjs.

iamveekthorr avatar Feb 22 '23 12:02 iamveekthorr

I think your problem is

const cacheStore = await cacheCollectionStore;

You don't that line, and I wonder where did you get that line from?

Without the await cacheStore.get() is undefined because cacheCollectionStore is a promise and doesn't have the methods resolved yet

rivaslive avatar Feb 22 '23 16:02 rivaslive

I think your problem is

const cacheStore = await cacheCollectionStore;

You don't that line, and I wonder where did you get that line from?

Without the await cacheStore.get() is undefined because cacheCollectionStore is a promise and doesn't have the methods resolved yet

i have fixed mine.

CacheModule.registerAsync({
      isGlobal: true,
      useFactory: () => {
        const options = {
          store: sqliteStore,
          name: 'cache',
          path: `cache.db`,
        };
       return caching(options);
      },
    }),

this worked for me.

iamveekthorr avatar Feb 22 '23 19:02 iamveekthorr

I think your problem is

const cacheStore = await cacheCollectionStore;

You don't that line, and I wonder where did you get that line from?

Without the await cacheStore.get() is undefined because cacheCollectionStore is a promise and doesn't have the methods resolved yet

i have fixed mine.

CacheModule.registerAsync({
      isGlobal: true,
      useFactory: () => {
        const options = {
          store: sqliteStore,
          name: 'cache',
          path: `cache.db`,
        };
       return caching(options);
      },
    }),

this worked for me.

Unfortunately I still have the same problem in Strapi. I guess this code is only for Nestjs?

rivaslive avatar Feb 23 '23 17:02 rivaslive

cacheManager.caching

I have not used strapi, so I have two questions:

  • In cacheManager.caching is the cacheManager the cache manager coming from require('cache-manager')?
  • If no, what is it?

In case it's standard cache-manager package then:

const cache = cacheManager.caching({
    store: sqliteStore,
    name: 'employees',
    path: '/tmp/cache.db'
})

should give you cache with get method you are looking for. What is confusing me is

  const cacheStore = await cacheCollectionStore;

Is it part of some new standard I am not aware of?

maxpert avatar Feb 23 '23 22:02 maxpert

cacheManager.caching

I have not used strapi, so I have two questions:

  • In cacheManager.caching is the cacheManager the cache manager coming from require('cache-manager')?
  • If no, what is it?

In case it's standard cache-manager package then:

const cache = cacheManager.caching({
    store: sqliteStore,
    name: 'employees',
    path: '/tmp/cache.db'
})

should give you cache with get method you are looking for. What is confusing me is

  const cacheStore = await cacheCollectionStore;

Is it part of some new standard I am not aware of?

This is the complete code.

const cacheCollectionSQLiteStore = cacheManager.caching({
    store: sqliteStore,
    options: {
      serializer: 'json',
      ttl: 60 * 60
    }
  });

  const dataCache = await cacheCollectionSQLiteStore.get('key_here');

This is error received. What am I doing wrong?

image

rivaslive avatar Feb 24 '23 05:02 rivaslive

cacheManager.caching

I have not used strapi, so I have two questions:

  • In cacheManager.caching is the cacheManager the cache manager coming from require('cache-manager')?
  • If no, what is it?

In case it's standard cache-manager package then:

const cache = cacheManager.caching({
    store: sqliteStore,
    name: 'employees',
    path: '/tmp/cache.db'
})

should give you cache with get method you are looking for. What is confusing me is

  const cacheStore = await cacheCollectionStore;

Is it part of some new standard I am not aware of?

This is the complete code.

const cacheCollectionSQLiteStore = cacheManager.caching({
    store: sqliteStore,
    options: {
      serializer: 'json',
      ttl: 60 * 60
    }
  });

  const dataCache = await cacheCollectionSQLiteStore.get('key_here');

This is error received. What am I doing wrong?

image

I think I was not clear enough what is cacheManager? How was it initialized?

maxpert avatar Feb 25 '23 16:02 maxpert

I think I figured out the issue. You are using cache-manager with v5 or higher. I noticed they have changed everything thing in v5 onwards, which might be causing the issue. I will get package updated and push out a new version with version v5 support.

maxpert avatar Feb 25 '23 16:02 maxpert

I think I figured out the issue. You are using cache-manager with v5 or higher. I noticed they have changed everything thing in v5 onwards, which might be causing the issue. I will get package updated and push out a new version with version v5 support.

cacheManager is default import from 'cache-manager';

rivaslive avatar Feb 25 '23 21:02 rivaslive

I think I figured out the issue. You are using cache-manager with v5 or higher. I noticed they have changed everything thing in v5 onwards, which might be causing the issue. I will get package updated and push out a new version with version v5 support.

I think that's the real problem, thanks for your good job. Blessings!

rivaslive avatar Feb 25 '23 21:02 rivaslive