One cache for different applications?

I have two applications: one is an asp.net site and the other is a windows service.

both applications link to my business layer (library project), which itself refers to my data access layer (library project), which itself uses the corporate library data application block to retrieve the data form from the SQL Server 2005 database.

I am currently using the System.Web.Caching.Cache object in my BL to cache some of my objects:

public static System.Web.Caching.Cache Cache { get { if(cache == null) { if (System.Web.HttpContext.Current != null) { //asp.net cache = System.Web.HttpContext.Current.Cache; } else { //windows service cache = System.Web.HttpRuntime.Cache; } } return cache; } } 

since both applications work independently - they both use a separate Cache object on their own - and this is actually a problem:

if I modify an object on asp.net website and save it to the database. the cache key object is removed from the cache - asp.net application cache! it's good.

but the windows service cache is becoming obsolete!

vice versa

Is it possible that both applications use the same Cache? One cache for both applications?

The only option I think of is that I will have to use SqlDependency with

Sql Server 2005 Invalid Notification Cache

Is there another way?

EDIT: I just found http://www.codeplex.com/SharedCache . I will give it a try. since the speed will be in the status of a candidate for release until mid-2009.

+1
source share
3 answers

You should take a serious look at Microsoft's new free distributed cache "Velocity".

Here is the podcast I did on this subject: http://www.hanselman.com/blog/HanselminutesPodcast116DistributedCachingWithMicrosoftsVelocity.aspx

Here are the details about MSDN: http://msdn.microsoft.com/en-us/data/cc655792.aspx

Samples are downloaded here: http://code.msdn.microsoft.com/velocity

+7
source

I think you need a distributed cache system like memcached. But there is more, just make a quick google and you will find what you are looking for.

http://www.google.com/search?q=distributed+caching

Hello,

Jochen

+2
source

The cache is only good for the application domain. Apparently, you cannot use the same cache between the web application and the web service. So, you need to make two caches in sync in various ways. Adding a cache dependency object to your caches as soon as the data has been changed will invalidate both cache elements and reload the object in caches. You can use polling or QN (much better performance) as a cache dependency mechanism.

0
source

All Articles