ASP.NET gurus, help over coming a problem RE Caching

  • Thread starter Thread starter Izi
  • Start date Start date

Izi

Izi

Soldato
Joined
9 Dec 2007
Posts
2,718
I have implemented caching in my application via Cache.Insert method. Objects are inserted with a key in to memory and are cleared on update or insert cmds.

The problem arrises with clustered hosting. If a website is clustered, then there are many IIS process. This means data in cache does not sync with each process.

I am at a loss and would like some ideas how I can over come this.

Currently caching is done in my BLL. My DAL is done using Linq.

I had thought of SQL Cache Dependancy, however the only way I could see this working would be at table level because I would need to create the SqlDependency object in my BLL.

Can anyone help with a solution to this?

A possible solution would be to move my caching to my DAL. this way I could get individual cmds at row level instead of table level?
 
Have you thought about using something like Memcached for .NET? http://www.infoq.com/news/2007/07/memcached

Alternatively, if you are running a web farm/garden, do you really care if you have 3/4/5/n different caches? Presuming you are using something like sticky sessions, the first time a user requests data, it will be stored in the Cache on the sticky server and the next time, fetched from the same cache.
 
Have you thought about using something like Memcached for .NET? http://www.infoq.com/news/2007/07/memcached

Alternatively, if you are running a web farm/garden, do you really care if you have 3/4/5/n different caches? Presuming you are using something like sticky sessions, the first time a user requests data, it will be stored in the Cache on the sticky server and the next time, fetched from the same cache.


thanks for the link.

It matters if each server has different caches as I dont want stale data. from the link you sent:

"A fundamental problem with caching is stale data. When running a single web server, one can easily clear a cache when data is known to have been changed. Unfortunately, ASP.NET doesn't have a good way to scale this up multiple servers. Each server's cache is blissfully unaware of changes to other caches."

the hosting is on TSO Hosts clustered solution, so dont have access to configurations.

The only way I can see this working is at table level, or row level using SQL cache dependanc, but it destroys the BLL / DAL be requiring the dependency to be done in dal as the SQL cmd is required to the SqlDependency class..


hmmmmmmmmm.
 
Caching can be tricky - you need to balance the possibility of serving stale data against the actual (business) cost of doing so. Generally I've found that force refreshing commonly changing data every X seconds works well, letting more static data sit for a much longer period.

And using something like Memcached means you have 1 application cache, no matter how many web servers you have, so you never have inconsistent state between your different app domains.
 
For a quick and easy way to deploy memcached try http://www.codeplex.com/memcachedproviders. You just add the provider to the web.config, and you can leave all your existing code alone.

If you want a full memcached client try http://www.codeplex.com/EnyimMemcached/

Memcached moves the cache from inside the asp.net worker process to a dedicated process (or indeed processes spread across servers) this allows it to be shared (either on the same server or between servers).

We use both Enyim and memcached providers in production systems.

akakjs
 
the hosting is on TSO Hosts clustered solution, so dont have access to configurations.
woops just re-read your reply I missed that, so it sounds like memcachedproviders won't be suitable.

akakjs
 
Back
Top Bottom