Welcome to Idea R | Branding - Web Agency - Digital Strategies
Switch to the mobile layout

      Idea R - Do others know who you are? Design your corporate identity
  • HomeHome
  • About UsAbout Us
  • ContactsContacts

Blog

Take a software geek from the 80s, add a new generation graphic designer and dilute with a longtime marketing strategist. Shake vigorously and you'll get the Idea R's blog.

Change language... italiano
Go to the blog summaryGo to the blog summary

You may be interested in

How to fix your ASP.NET site to be responsive on Windows Phone

How to fix your ASP.NET site to be responsive on Windows Phone

Internet Explorer 10 for Windows Phone 8 suffers a bug when displaying responsive web sites. See how to fix it server-side with few lines of code.

Lazy loading and the SEO problem, solved!

The best SEO solution to index your dynamically loaded contents, no more compromises!

Last published

[FREE download] Keywords Mixer: long tail keywords made easy

[FREE download] Keywords Mixer: long tail keywords made easy

There's a basic implementation inside Google AdWords Editor, but this tool will give you more control over permutations and long tail keywords.

Case study: advertising B2B maintenance

How is it difficult to advertise maintenance services in B2B? Let's explore this case study and discover secrets and most common mistakes.

Most popular

Milano Design Week 2017, Design Districts

Milano Design Week 2017, Design Districts

Ventura Lambrate and Tortona, here are the best creations that we discovered in the 2 districts of the Fuorisalone Milan Design Week 2017.

Case study: TAV Engineering, branding for B2B services

How to create a brand that keeps distance from the cold and aseptic image of the metal industry, focusing instead on the human aspect.

Editor's pick

Case study: branding and marketing for a magician

Case study: branding and marketing for a magician

Singular case study in the world of illusionism. See how we have created a brand and a web marketing campaign with exceptional results.
Mental marketing secret #1: the fake compromise

Mental marketing secret #1: the fake compromise

Can mentalism influence marketing? As a marketing professional and a long term magician, I will reveal you some tricks.
newsletter

Stay informed on digital strategies

Take a look at the last published articles
RSS feed

How ASP.NET can efficiently control the client cache

Published on 6/12/2013
Categories: Web Design
How ASP.NET can efficiently control the client cache

In this article we will see how to precisely control the cache of the client (the browser of your PC, for example) in order to avoid the transmission of data from the server when the client already owns them. The ASP.NET server already has systems for data caching, for example to avoid repeating the same database query; would not it be nice not to avoid sending these data to avoid bandwidth consumption?
The technique is called conditional GET and uses the 304 HTTP status code and in practice implements the following dialogue between client and server:

Client: "Hello server, I need some data. The last time you gave them to me, you told me they were update to the following date/time"

At this point, the server checks the provided date/time and, whether the data are changed, it responds:

Server: "Hello client, the data have changed since then, here's the new ones. If you need them again in future, note that data are update to the following date/time."

or

Server: "Hello client, the data have not changed since then, so I avoid send them again, you have them in your cache."

This type of optimization is particularly useful when data are dynamically generated on the server side and change during the time.
Let us transform this dialogue in C# code, using the example of an HttpHandler that generates a RSS file dynamically (that's what happens when you subscribe to the RSS feeds of this blog). In this example we do not address the topic of ther dynamic generation of RSS feeds, as this would be beyond the scope of the article, but we'll just see how to implement the conditional caching.
Let's assume that the method GetLastBlogUpdateDateTime() returns the UTC date/time of the last blog update.

public class BlogRssHandler : IHttpHandler, IRequiresSessionState
{
    public virtual void ProcessRequest(HttpContext Context)
    {
        // If the client already has the updated RSS, do not send it again
        if (BuildResponseHeader(Context) == false)
            return;
        else
        {
            // Generate the RSS feed
            ...
        }
    }
 
    // Returns false if contents can be retrieved from the browser's cache
    // (HTTP response 304 optimization)
    private Boolean BuildResponseHeader(HttpContext Context)
    {
        // Get the last modification date/time stored in the database
        // NOTE: the date/time must be UTC
        DateTime serverLastUpdateUTC = GetLastBlogUpdateDateTime();
 
        // Get the last modification date provided by the browser (if any)
        String ifModifiedSinceHeaderText = Context.Request.Headers.
            Get("If-Modified-Since");
        if (!String.IsNullOrEmpty(ifModifiedSinceHeaderText))
        {
            DateTime clientLastUpdateUTC = DateTime.Parse(ifModifiedSinceHeaderText);
            clientLastUpdateUTC = clientLastUpdateUTC.Value.ToUniversalTime();
 
            // If the modification date/time of the client is equal to the server one
            if (serverLastUpdateUTC <= clientLastUpdateUTC)
            {
                // ...tell the browser that contents have not changed and return
                Context.Response.ClearContent();
                Context.Response.StatusCode = (Int32)
                    System.Net.HttpStatusCode.NotModified;
                Context.Response.StatusDescription = "Not Modified";
                Context.Response.SuppressContent = true;
                return false;
            }
        }
 
        Context.Response.ContentType = "text/xml";
        // Tell the browser to cache the new contents
        Context.Response.Cache.SetCacheability(HttpCacheability.Private);
        Context.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
        Context.Response.Cache.SetLastModified(DateTime.SpecifyKind(
            serverLastUpdateUTC.Value, DateTimeKind.Utc));
        // Force the browser to not use it's current cache
        Context.Response.Cache.SetMaxAge(new TimeSpan(0, 0, 0));
        Context.Response.Cache.SetExpires(DateTime.Now.ToUniversalTime());
        return true;
    }
 
    ...
}

When the server sends the date/time to the client it is better to round it removing milliseconds.
It 'also important to specify that the date/time is UTC (DateTime.SpecifyKind method), this thing is not mentioned in some examples around the web, but it is very important.

You are the reader number 7,178.

Comments

Creative Commons License

Photographies, videos, graphics and texts by Idea R are licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.

Previous article

Previous article

Case study: TAV Engineering, branding for B2B services

Next article

Wonderbra, advertising without clothes and without... models

Next article
  • Visual Communication, Art DirectionVisual Communication, Art Direction
  • Apps, Cloud, Mobile, Software DesignApps, Cloud, Mobile, Software Design
  • Digital StrategiesDigital Strategies
  • BlogBlog
Touching finger
RSS feed
Blog

Scroll to top