Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Using Redis to cache query result #8480


User avatar
0
dev_frontrush created

What is the best way to cache the results of a query that would contain potentially tens of thousands of records? The use case is that a search listing screen would call the API where the base results are cached, retrieve the results, filtered based on user input, and return the filtered data to the user. The current implementation is saving the result set as an extremely long string and the performance is significantly worse than not using caching at all. In fact, from the Azure Redis Cache, it is taking ~2.8s to return the cached string. Note that a much simpler, and smaller cache was setup as a baseline and it seems to perform as expected, in that the response time was slightly faster than if no cache was used.. Please advise.


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @dev_frontrush

    It is hard to say something without seeing the entire code but you can also try Memory Cache if it is suitable for your use case, https://aspnetboilerplate.com/Pages/Documents/Caching

  • User Avatar
    0
    dev_frontrush created

    To possibly phrase my question in a different way, I am looking for best practice on how to cache a large list of items returned from a base query. I mentioned Redis because when I changed from InMemory cache to use the Redis server, the performance suffered quite a bit. I then realized it was storing the cached list as a really long string representing the serialized objects. I have seen that you can save objects as a List vs. a String, but do not see any examples of implementation in your documentation, which I had already read.

  • User Avatar
    0
    maliming created
    Support Team

    hi @dev_frontrush

    What is your abp version?

    You know that Abp's redis cache is to serialize objects into strings and store them in redis. Deserializes the string into an object when reading the cache.

    You can directly use the redis api to use other redis cache types. In some cases performance may be higher than abp. Because abp sacrifices some performance for generality.