I'm working on fetching huge amount of data(millions of records) and plan is to keep frequent records in cache and fetch from cache for quick responses. I'm using NoSQL database and have around 35k records in the cache. I'm using this piece of code to check if its cached,
redistemplate.opsForHash().entries("key").size() == 0,
if the condition satifies,
redistemplate.opsForHash().put("key", "KeyValue", List);
if not,
(List) redistemplate.opsForHash().entries("Key").get("KeyValue");
But when I'm checking the performance, fetching from DB is faster than fetching from cache. I'm just trying the basic redis caching, not sure if it is recommended. Please provide inputs.
You are dealing with entries.. why !? You can use template function directly to access keys or values.
To check the condition:
redisTemplate.hasKey("key");
if doesn't satisfy:
redistemplate.opsForHash().put("key", "hashKey", List);
else
redisTemplate.opsForHash().get("key", "hashKey");
I think this will enhance the performance.
on the other hand, try to find where the delay exactly is. ie. which call is causing the delay?
I made another way of resolving it, instead of OpsForHash, I tried OpsForList which is much faster.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With