ASP.NET MVC Caching Script

I have yet to find a decent solution for my scenario. Basically, I have an ASP.NET MVC website that has a fair bit of database access for creating views (2-3 queries for each view), and I would like to use caching to improve performance.

The problem is that the views contain data that can change irregularly, for example, it can be the same for 2 days or the data can change several times per hour.

Queries are fairly simple (select ... where), rather than huge joins, each of which returns an average of 20-30 rows of data (about 10 columns).

Requests are quite simple at the current stages, but over time, the owner will add more data and the number of visitors will increase. They are large at the moment, and I would look at caching, since the traffic will come mainly from Google AdWords, etc., and the quick loading pages will be useful (apparently).

The site will be hosted in a Microsoft SQL Server 2005 database (but may require upgrading to 2008).

I also:

  • Set the caching at the minimum time when the item does not change (for example, the cache in 3 minutes) and tell the owner that any changes will appear before 3 minutes?

  • Find a way to force the cache to clear and process the changes (for example, if the owner adds an item in the administration panel, it clears the corresponding caches)

  • Forget about caching together

  • Or is there an option that will fit this scenario?

+6
c # caching asp.net-mvc
source share
3 answers

If you are using Sql Server, there is another option:

Use the SqlCacheDependency class to make your cache invalid when updating base data. Obviously, this gives a similar result for option 2.

I could actually agree with Agileguy, although your query descriptions seem pretty simplistic. Thinking ahead and keeping caching in mind when you are developing is a good idea, but have you proved that you really need it now? Option 3 seems a hell of a lot better than option 1, assuming you don't really have serious performance issues right now.

+5
source share

Premature optimization is the root of all evil;)

However, if you are going to Cache, I would use a solution based on option 2.

You have less opportunity for dirty data in this way.

Kindness,

Dan

+4
source share

The second option is the best. It should not be so difficult if the same application edits / caches data. It can be more difficult if there are several applications.

If you cannot go this way, 1st may also be acceptable. With some settings (i.e., I would try to update the cache silently in another thread when it reaches the timeout), it can work quite well (if the data can be a bit old).

Never discard caching if possible. Everyone knows about "premature optimization ...", but caching is one of those things that can significantly increase the scalability / performance of an application.

0
source share

All Articles