Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I implement Caching Strategy in my Asp.net Mvc With linq2sql repository?

I dont know if I should use the httpcontext caching or the Enterprise Library Caching Application Block. Also, what is the best pattern for the caching Strategy when deleting or updating an entity that is part of a cached list?

Should I remove all of a list from the cache or only remove the item from the cached list? If I update it will I remove the list from the cache or update the entity in it.

like image 274
Moran Helman Avatar asked Oct 13 '08 21:10

Moran Helman


People also ask

Does ASP NET Core support distributed caching?

ASP.NET Core works with SQL Server, Redis, and NCache distributed caches. For more information, see Distributed caching in ASP.NET Core. Cache the content from an MVC view or Razor Page with the Cache Tag Helper. The Cache Tag Helper uses in-memory caching to store data.

What are the different levels of caching in ASP NET?

ASP.NET provides the ability in terms of caching at various levels. 1. Page Level Output Caching This is at the page level and one of the easiest means for caching pages. This requires one to specify the duration of the cache and the attribute of caching.

Is there a cache in ASP NET?

In the .NET Framework 3.5 and earlier versions, ASP.NET provided an in-memory cache implementation in the System.Web.Caching namespace. In previous versions of the .NET Framework, caching was available only in the System.Web namespace and therefore required a dependency on ASP.NET classes.

How to cache the content of the action method in MVC?

In ASP.NET MVC we can specify where we want to cache the content of the action method. To use caching in the action method we use the OutputCache attribute and specify the Duration and VaryByParam arguments. The following code will cache the contents of the action method for 1 minute.


1 Answers

Having done some testing with both I did a full review of the caching application block in the context of our code and blogged my experience with it. It's very simple to use and powerful enough for our needs. I would recommend it, my results were blogged here.

In your position I would use the Repository pattern to maintain my cache, it works well for database datasets and should work equally well for the cache in your own. If you're not familar with the repository pattern, check out this post from Steven Walther.. I would tend to disagree with the previous answer however, taking out only the items you need for modification and laeving the rest untouched. This will allow you to expire items from the cache independantly from the whole list should you so wish.

like image 116
Odd Avatar answered Oct 26 '22 13:10

Odd