When developing multi user applications like website we potentially dealing with lots of concurrent requests. And naturally we want to cache the results of expensive methods:
public int GetUsersCount ()
var cache_key = "UsersCount";
var users_count_obj = this.cache.Get (cache_key);
if (users_count_obj != null)
return (int) users_count_obj;
var users_count = GetUsersCountFromDb ();
new CachingParameters (TimeSpan.FromMinutes (15)));
This method uses Rocks.Caching.ICacheProvider that I blogged before about. Basically, the we write cache code like this:
- Try get result from cache
- If the result is not null return it
- Otherwise calculate the result
- Add the result to the cache
- Return the result
Now, it works for most of the time until we starting to get a lot of concurrent requests for the same method. The problem is point 2 and 3.
I’ve recently published source code of one my libraries that I use in many home and production projects. It’s called Rocks.Caching and it’s part of my “Rocks” libraries collection that targeted to gather all my best practices in different features implementations. You can also find it on nuget.
Domain Driven Design is the thing most of us (developers) stumble upon at some point of their career. There is quite number of books and posts about this topic and a couple of big communities. Developers starting exploring DDD work (probably from Eric Evan “Blue Book”) and many of them became convinced how good this DDD thing is. And they are right – DDD is awesome but just like any tool it’s awesome only in some circumstances and only for specific kind of work. Just like poor knowledge can lead to bad smelly code, applying complex methodologies without knowing their cons can make the code even less maintainable.
First post on my blog. Well, it has to start somewhere, isn’t it?
There are a number of articles about how you should design you web application. And in many of them there is a recommendation to invest in building repository for data access. And that’s where I think many new developers got wrong impression about what exactly the repository is.