18

I have got some tabular data that due to unrelated issues is proving too slow to get out of SQL Server in realtime. As we get more users this will only get worse so I am thinking of using Redis as a front-end cache to store users' tabular pageable data.

This data could become stale after about 10 minutes after which time I would like to get the record set again and put in in Redis.

The app is an .NET MVC app. I was thinking that when the user logs into the app this data gets pulled out of the database (takes around 10 seconds) and put into Redis ready to be consumed by the MVC client. I would put an expiry on that data and then when it becomes stale it will get refetched from the SQL Server database.

Does this all sound reasonable? I'm a little bit scared that:

  1. The user could get to the page before the data is in Redis
  2. If Redis goes down or does not respond I need to ensure that the ViewModel can get filled direct from SQL SErver without Redis being there
5
  • 1
    Victoria, you may find this post interesting. Around minute 15 he shows a possible approach for integrating Redis. Commented Jan 30, 2012 at 22:02
  • 1
    @uvita can you add this as an answer as I would like to accept it - is the perfect solution I was looking for Commented Feb 1, 2012 at 16:57
  • @Victoria Have you considered implementing the cache-aside pattern? Commented Jan 13, 2017 at 12:57
  • 1
    Also, are you using Entity Framework? You may want to consider using EntityFramework.Extended. It's default caching mechanism will allow you to cache data locally on your web application server, which is quite fast. However, if you want to be able to horizontally scale out your solution, you can develop a custom caching provider for it to use. github.com/loresoft/EntityFramework.Extended Commented Jan 13, 2017 at 13:01
  • @Victoria I would like to know what exactly you did for the solution with Redis, I am also trying to do a similar kind of work with Redis. Commented Apr 26, 2022 at 18:50

2 Answers 2

6

I will go for Service stack redis implementation, here are all the details required. Redis is particularly good when doing caching in compare to other nosql. But if you are having high read - write application, I will insist to check out nosql database as database combined with SQL server. That will help in case of scalability.

Please let me know if any further details required. You just need to fire nuget command and you are almost up and running.

Sign up to request clarification or add additional context in comments.

Comments

4

You could use something like MemcacheD to store cached pages in memory.

You can set a validity of 10 minutes on a cached object. After that the cache will automatically remove the object.

Your actual repository would have to do these steps:
1. Check the cache for the data you want, if it is there, great use it
2. If the cached data doesn't exist, go to SQL server to retrieve it
3. Update the cache with data returned from SQL server

I've used the Enyim client before. It works great. https://github.com/enyim/EnyimMemcached

I might also use something like Quartz to schedule a background task to prime the cache. http://quartznet.sourceforge.net/

1 Comment

I like your idea of Redis as a cache too. The implementation of Redis would be very similar to Memcached... some people say that it is just as fast or faster and it has more features. I just can't recommend it because I've never worked with it outside of some NodeJS demo apps

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.