Closed amtarunsingh closed 2 years ago
Can you check if you're using version 2.0.0
? Previous version had a bug
The version is 2.0.0.
Do you think you can provide a reproduction? A repo or some simple code? Without more information I don't know what's going on there.
Can you also explain more what do you mean by
cache is not reflecting in the redis UI
this is how am connecting: const { MikroORM } = require('@mikro-orm/core/MikroORM'); const {RedisCacheAdapter} = require('mikro-orm-cache-adapter-redis') const Redis = require('ioredis');
let redisClient = new Redis('MY_REDIS_STRING_HERE'); const config = { resultCache: { enable:true, adapter: RedisCacheAdapter, options: { client: redisClient } } };
const orm = await MikroORM.init(config)
Do i need to do anything else apart from this in the find() method of mikrorm?
currently my find method is like : let [products, count] = await orm.em.findAndCount(Product, findQuery, paginationQuery); Product is the name of my entity(repo).
but am not able to see the data in my Redis database. is there something am doing wrong or missing out something?
Oh yes, you have to tell MikroORM you want to cache results: https://mikro-orm.io/docs/caching
await orm.em.findAndCount(Product, findQuery, paginationQuery, {cache : true}); Like This?
Yes. Consider the default cache time is 1 second, so you may still miss it on redis UI if you're not fast enough
I have changed my find query to this : let [products, count] = await coll.findAndCount(query, paginationQuery, {cache:true});
and has increased the cache time to 100000:
resultCache: {
enable:true,
expiration:100000,
adapter: RedisCacheAdapter,
options: {
client: redisClient
}
}
but still the data is not visible in the redis database.
but still the data is visible in the redis database.
Do you mean is NOT visible?
Anyway, I think I need some reproduction code
mikrormCache.zip Sir this is the code. Please have a look.
Hello. I finally had tie to look at your code. I found the error
let [products, count] = await coll.findAndCount(query,paginationQuery,{
cache: true,
});
is wrong, there's not a third option. The correct signature of the function is
let [products, count] = await coll.findAndCount(query, {
...paginationQuery,
cache: true,
});
You should use typescript to avoid these errors
I also released a new version of the cache adapter that can be used with mikro-orm v5
Also, if you want to see what the cache is doing, you can pass debug: true
to the options
Thank you .
I have made the connecting and updated init config in the in the mikrorm.init ({}). but my cache is not reflecting in the redis UI, is there anything that I have to do at the time of finding?
My cache config: