Monday, December 19, 2011

Caching through Aspect oriented annotations.

I spent part of the day today instrumenting some of our DALC (data access methods) with caching using the typical paradigm:

public Data FetchData(string key) {
if (cache.HasKey(key)) {
return cache[key];

Data d = GrabFromDB(key);
cache[key] = d;
return d;

It is a pain, because every single method needs to be instrumented with the same preamble. My next step was to try to use reflection to dynamically modify the generated C# IL code.

A few hours later, I came across this elegant solution using Aspect oriented programming (AOP):

Postsharp framework allows you to define custom annotations, so that instead your code becomes

public Data FetchData(string key) {
return GrabFromDB(key);

The problem is that the key "FetchData" is not dynamic, and instead must depend on the value of the parameter. There turns out to be a nice solution to that as well :

I am going to try it out tomorrow, but it's looking quite promising.



Interesting, but if you want use it in real applications it's important define some data management policies or scope (e.g. range time, session or application scope ...)

Of course.
The second link to a blog in SharpCrafters gives a nice example. I am testing this right now with using REDIS as a cache store, and the entries timing out after a while. So far my results are looking promising and all I have to do to cache method results is add a [Cache] annotation.

As a result of continually strenuous perform daily activities and also omega replica uk family obligations in which must be happy, a single will not constantly acquire time and energy to catch up with his / her favored Series, specifically stay sports game titles. Often times, these kinds of sports game titles are usually both noted or perhaps overlooked entirely. Yet even when the sport will be noted, the particular omega replica uk regarding observing the first STAY actions lowers by 50 percent for the duplicate telecast. Nonetheless, as a result of the net, it's simple to observe NFL game titles on the web, without having to overlook every one of the fantastic sports hublot replica sale, regardless of where you might be. That is for the reason that although you may are usually overseas and don't have got TV SET accessibility, if you have world wide web on-line within your place, it is possible to quickly convert your personal machine in to the best sporting activities cartier replica system while not having to watch for the particular repeats. More, this kind of provision to look at NFL game titles on the web may be exercised coming from anywhere in the world! Thus although you may certainly are a repeated flier that is constantly around the cartier replica sale, the notebook can now hook up one to uninterrupted STAY actions of one's favored sports game titles from your NFL!

Java Online Training Java Online Training Java Online Training Java Online Training Java Online Training Java Online Training

Hibernate Online Training Hibernate Online Training Spring Online Training Spring Online Training Spring Batch Training Online Spring Batch Training Online

Java Training Institutes Java Training Institutes Java EE Training in Chennai Java EE Training in Chennai Java Spring Hibernate Training Institutes in Chennai J2EE Training Institutes in Chennai J2EE Training Institutes in Chennai Core Java Training Institutes in Chennai Core Java Training Institutes in Chennai

The blog or and best that is extremely useful to keep I can share the ideas
of the future as this is really what I was looking for, I am very comfortable and pleased to come here. Thank you very much.
tanki online | 2048 game| tanki online game

Post a Comment