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

[Bug] store.get is not a function #3

Open
rivaslive opened this issue Feb 18, 2023 · 11 comments
Open

[Bug] store.get is not a function #3

rivaslive opened this issue Feb 18, 2023 · 11 comments

Comments

@rivaslive
Copy link

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

@maxpert
Copy link
Owner

maxpert commented Feb 20, 2023

I think your problem is

const cacheStore = await cacheCollectionStore;

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

@iamveekthorr
Copy link

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.

@rivaslive
Copy link
Author

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

@iamveekthorr
Copy link

iamveekthorr commented Feb 22, 2023

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.

@rivaslive
Copy link
Author

rivaslive commented Feb 23, 2023

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?

@maxpert
Copy link
Owner

maxpert commented Feb 23, 2023

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?

@rivaslive
Copy link
Author

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

@maxpert
Copy link
Owner

maxpert commented Feb 25, 2023

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
Copy link
Owner

maxpert commented Feb 25, 2023

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.

@rivaslive
Copy link
Author

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
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants