views:

80

answers:

4

I recently received a project that contains multiple web applications with no MVC structure. For starters I've created a library (DLL) that will contain the main Business Logic. The problem is with Caching - If I use the current web context cache object than I might end up with duplicate caching (as the web context will be different for every application).

I'm currently thinking about implementing a simple caching mechanism with a singleton pattern that will allow the different web sites (aka different application domains) to share their "caching wisdom".

I'd like to know what is the best way to solve this problem.

EDIT: I use only one server (with multiple applications).

A: 

Sounds to me like you should take a look at Build Better Data-Driven Apps With Distributed Caching. The article describes a new, distributed cache from Microsoft (codenamed Velocity).

Morten Mertner
I'm not sure it's good for one server solution.
Eran Betzalel
+1  A: 

Depending on the type and size of the data you want to cache, I'd suggest:

  1. For small amounts of primitive data : nCacheD (codeplex) - memcached redux for .net
  2. For heavyweight objects : MS Patterns and Practices Caching Block (msdn)

In general though, I would look at my requirements and make really sure an all-encompassing cache is really needed, and writing code to maintain its state (and tune its resource consumption) would not be more expensive than going straight to the database. If most of the stuff you want to cache is static pages, or a combination of static & dynamic content, I would look into utilizing IIS/ASP.NET's page level cache.

Dobriak
If am not mistaken nCacheD is mainly used to maintain cache among several servers. I've only one server with multiple applications, so it looks like an overkill for my problem.
Eran Betzalel
memcached (checkout memcached.org) is a distributed key->value cache, you can run it on only 1 or as many as you want servers.
Dobriak
A: 

I've also been offered to use SharedCache, which look exactly like the architecture I'm looking for: Single Instance Caching.

Eran Betzalel
+1  A: 

I have two different suggestions depending on your plans to be scalable. Regardless of the back end cache you choose i would suggest that you first implement an adapter pattern layer that abstracts you from your cache, as a result it will limit your dependency on the cache and give you the ability to swap it out later.

If you want to scale out by adding a web farm (more than one application server) then look at velocity. Microsoft will be packaging this in 4.0 but it is a CPT3 currently and is very easy to use.

Documentation

Download

If you dont plan to move to a multiple server system then just use the HttpContext.Current.Cache

Nix
HttpContext.Current.Cache is per application, I've several applications on one server - meaning that every application will have its own Cache, which is the problem I'm trying to solve.
Eran Betzalel
Then velocity is your (free)answer.
Nix