The Premier Event for Search Engine
Marketing & Optimization -
Register Now

Web News

Google Finance stock-tracker hits the UK
Google has officially launched a UK version of its Google Finance stock-tracking system. The company said that the new service will have special settings and features to cater for UK investors. Unique features of the UK...

YouTubers given share of ad cash
YouTube users in the UK will be given the chance to make money from the videos they post on the site. The project is already up and running in the US and is now being extended to other countries, starting in the UK. In the US some contributors are already earning...

UK property search engine aims to break into US market
British property search engine Dothomes is expanding its scope dramatically in an attempt to take on the lucrative US market. Less than two years after being founded, Dothomes' parent company BytePlay said it was ready...

Bill Gates advice to UK wannabes? Don't get sued
Bill Gates performed the London leg of his farewell tour this morning, telling aspiring entrepreneurs they should sign up to Microsoft's CRM platform and to try not to get sued. Gates took to the stage at the Institute of Directors as the Eighties soft rock classic The Final...

New broadband minister announced
Broadband users may be interested to learn that their internet provider will now be monitored by Baroness Shriti Vadera. The Baroness's new position as Parliamentary Under Secretary of State for Business and...

No 120GB PS3 for UK, says Sony
Sony Computer Entertainment Europe has told our sister site GamesIndustry.biz there are no plans to introduce a 120GB PlayStation 3 round these parts. Rumours such a model will appear in the US began circulating earlier in the week. According to Ars Technica, it'll come with...


01.31.08

Caching & Whether Or Not To Use Absolute Or Sliding Expiration

By Mads Kristensen

I'm in doubt and I need your help on this important subject. It's about caching and about whether or not to use absolute or sliding expiration.

I've been thinking really hard about this and can find both pros and cons to each solution. This scenario is this:

When the BlogEngine.NET application starts, it loads all posts into memory. Because BlogEngine.NET is a single-blog-per-installation it doesn't really matter much since each post only use about 50kb of memory. So my 350 posts only use about 17.5MB of RAM. However, some people have thousands of posts even on a single installation. The goal is to reduce the memory footprint by using intelligent caching.

The simplest solution is to take the post body - the text of a post - and make it lazy loaded, so it only loads when it is requested by a visitor. By lazy loading I mean that the body is read from IO whether it is from a database or XML file only when it is requested instead of put into memory when the application starts.

The post body is by far the biggest entity on a post and therefore is the single most influence on memory consumption.

Sliding expiration

What I've done is to cache the post body with a sliding expiration of 3 minutes. That means that when a visitor requests a particular post, the body is cached for three minutes from that point on. One minute later, another visitor requests the same post and then the cache expiration is reset to 3 minutes again and so on.

The problem with this approach is if you have a rather popular blog where people requests a lot of both new and old posts. Then you might end up with a solution where almost all post bodies are cached all the time and never expires. On the positive side the performance remains high since no IO loading occurs because all post bodies are loaded into memory.

The Premier Event for Search Engine
Marketing & Optimization -
Register Now

For lesser popular blogs, another positive is that all the rarely visited posts are removed from cache but the front page still loads directly from memory most of the times.

Absolute expiration

The other possibility is to use an absolute expiration of 3 minutes as well. That means that no matter how many requests a post gets, the cache always expires after 3 minutes after the first request. The problem here is if you have a popular blog, then the performance takes a hit since it has to read from IO every 3 minutes on every post. The positive thing is that you clear the cache very frequently to garbage collection.

Another issue with this solution is that for a new blog with few requests, the performance hit will be the biggest. It has to do IO reads at almost every request since there are more than 3 minutes between each request. As I see it, absolute expiration will reduce memory consumption most, but take the biggest performance hit.

Your suggestion

There are pros and cons with each solution and I can't figure out what makes the most sense. I lean toward sliding expiration since it will make sure the front page always loads from memory, but then again, it also keeps certain posts in memory all the time.

What is your take on this issue and are three minutes the right expiration time span?

Comments


About the Author:
Mads Kristensen currently works as a Senior Developer at Traceworks located in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in 2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and web services in his daily work as well. A true .NET developer with great passion for the simple solution.

http://www.madskristensen.dk/

About DevWebProUK
DevWebProUK is for professional developers ... those who build and manage applications and sophisticated websites. DevWebProUK delivers via news and expert advice New Strategies In Development.

DevWebProUK is brought to you by:

SecurityConfig.com NetworkingFiles.com
NetworkNewz.com WebProASP.com
DatabaseProNews.com SQLProNews.com
ITcertificationNews.com SysAdminNews.com
LinuxProNews.com WirelessProNews.com
CProgrammingTrends.com ITmanagementNews.com


-- DevWebProUK is an iEntry, Inc. publication --
iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509
2008 iEntry, Inc.  All Rights Reserved  Privacy Policy  Legal 

archives | advertising info | news headlines | free newsletters | comments/feedback | submit article


Delivering IT Solutions DevWebProUK News Archives About Us Feedback DevWebProCanada Home Page About Article Archive News Downloads WebProWorld Forums Jayde iEntry Advertise Contact