Welcome to my WebLog

The virtual home of Alon Fliess

<December 2008>
SuMoTuWeThFrSa
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910


Navigation

Sela

Subscriptions

News

It is impossible to know everything, but we should try!

Article Categories



Controlling Output cache

I have heard a lecture of David Platt about ASP.Net 2.0 that was held as part of the ASP.Net 2.0 tour. He talked about the new @SQLDependency directive that allows a Web Form cache to be invalidated according to a database table changes. At first this looked like a great cache policy improvement, but then many people in the audience have realized that it leads to coupling of the Presentation Layer with the DB layer as opposed to using the middle tier business logic layer. For example if I change the database schema, I have to go and change the SQLDependency tag on each and any page that uses it. Another issue that came up was whether the SQLDependency support other databases such as Oracle.

The answer to all those questions is that the cache mechanism is capable to any custom policy even on ASP.Net 1.1, You just have to register a delegate to set your own policy:

This example is extracted from the documentation:

public void Page_Load()

{

      Response.Cache.AddValidationCallback(new HttpCacheValidateHandler(Validate), null

}

public void Validate(HttpContext context, Object data, ref HttpValidationStatus status)

{

      if (context.Request.QueryString["Valid"] == "false")

      {

         status = HttpValidationStatus.Invalid;

      }

      else if (context.Request.QueryString["Valid"] == "ignore")

      {

         status = HttpValidationStatus.IgnoreThisRequest;

      }

      else

      {

         status = HttpValidationStatus.Valid;

      }

}

So feel free to create your own cache policy.

The only ability that I think that the ASP.Net @ directive is missing is the ability to add my own directives that will change the policy, something like:

@MyDependency …

For example, they could let us create a custom attribute that we could put in the page <% %>

 

Alon.

posted on Sunday, February 20, 2005 12:59 PM by alon





Powered by Dot Net Junkies, by Telligent Systems