We help IT Professionals succeed at work.

Caching patterns in ASP.NET with EF4

Hi to all .NET masters,

My question is about caching patterns in ASP.NET 3.5/4.0. In my web project I am using EF4 as my data model layer, Repository as DAL and Service Layer for the business logic.
I want to know which Data Caching would be best appropriate for this type of project.

I thought about using SqlCacheDependency with pooling but this one would only work for caching whole tables, and hence is not really useful.
Another option is using SqlCacheDependency with notifications, but it seems that it has problems with queries which are being produced by the EF4.
Last option I though is using simple HttpContext.Cache. But this way it would be really hard to invalidate cache when data is modified from various applications and not only the main web application.

I would really like to know what do experts use in their big projects. Please notice that all layers I presented are in different projects in my main solution.

Thanks,
Sagi
Comment
Watch Question

Scrum Trainer | Microsoft MVP | ALM Ranger | Consultant
Commented:
If you externalize your cache, usign AppFabric Cachign for example, and then share the cache across applications, you're safe.

Otherwise, just use the cache for simple displaying of data, but when a user wants to edit something, request a fresh copy.

Using SqlCacheDependency works great if you have a dedicated database nearby, but for larger databases and larger scale, you need to have a caching strategy that knows how te deal with stale data.

Author

Commented:
Hi,

Thanks for the reply. The simple method you've described in paragraph 2 is not applicable because I have external applications which also access the same db and need to invalidate cache entries (such as admin panel).

Regarding AppFabric, I am hearing more and more about it. You mean the cloud cache? Or installing some kind of cache mechanism on my VDS and being able to access it from all apps?

I've also heard about memcached. Have anyone used it and can say something about it? Is it the same as the AppFabric or are they different concepts?

Thanks,
Sagi
Jesse HouwingScrum Trainer | Microsoft MVP | ALM Ranger | Consultant

Commented:
AppFabric server is the 'azure counterpart' of the distributed caching mechanism:
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=15848

It has a lot in common with MemCached, AppFabric is the free supported Microsoft version.

Author

Commented:
So basically I just install it on my VDS, and I will be able with some providers access it's global cache entries (get, remove, add etc')?
Jesse HouwingScrum Trainer | Microsoft MVP | ALM Ranger | Consultant

Commented:
That's the idea, and you can install additional nodes, so if you want to, you can run nodes in multiple datacenters, or have dedicated nodes for specific applications.

Author

Commented:
By nodes you mean, different instances of the cache maps?
In few words, What is the meaning of running it in different datacenters?

Also, would you recommend using it over memcached? If so, why?
Jesse HouwingScrum Trainer | Microsoft MVP | ALM Ranger | Consultant

Commented:
AppFabric Cache supports distributed caching, you're not required to do this, but you can. This means you can use one central cache machine, or distribute the cache to different machines. These machines must be able to talk to eachother, but don't have to be on the same physical location.

memcached and a few other systems provide similar functionality. Personally I haven't used them, as AppFabric Server is a supported addition to the Windows Server platform. Meaning you are covered for support calls, some form of compatibility guarantees etc by Microsoft.