ASP.NET Podcast Show #129 - Caching with .NET 3.5 SP1

Subscribe to All!

Subscribe to WMV.

Subscribe to M4V (iPod).

Subscribe to MP3.

Download WMV.

Download M4V (iPod).

Download MP3.

Original Url: http://aspnetpodcast.com/CS11/blogs/asp.net_podcast/archive/2008/12/04/asp-net-podcast-show-129-caching-with-net-3-5-sp1.aspx

Show Notes:

  • New Caching Support in .NET 3.5 SP1.

Source Code:

    protected void Page_Load(object sender, EventArgs e)

    {

        string Output = String.Empty;

        if (!Page.IsPostBack)

        {

            lblOutput.Text = GetCacheItem();

        }

    }

 

    private string GetCacheItem()

    {

        string OutValue = String.Empty;

        if (Cache["Test"] != null)

        {

            OutValue = Convert.ToString(Cache["Test"]);

        }

        else

        {

            OutValue = DateTime.Now.ToString();

            Cache.Insert("Test", OutValue, null,

                DateTime.Now.AddSeconds(10),

                TimeSpan.Zero, OnUpdateCallback);

        }

        return (OutValue);

    }

    private void OnUpdateCallback(String key, CacheItemUpdateReason r,

        out Object ObjectToCreate, out CacheDependency CacheDependencies,

        out DateTime DateTimeExpire, out TimeSpan TimeSpanExpire)

    {

        ObjectToCreate = DateTime.Now;

        CacheDependencies = null;

        DateTimeExpire = DateTime.Now.AddSeconds(10);

        TimeSpanExpire = TimeSpan.Zero;

    }

 

1 Comment

  • Hi,

    Great news.

    I wrote some other tricks about ASP.NET Caching.

    Check this out :

    http://blog.sb2.fr/post/2008/11/21/EN-Css-Caching-and-Compression-with-HttpModule-for-ASPNET.aspx

    http://blog.sb2.fr/post/2008/11/25/Useful-Cache-and-Session-Method-Extensions-for-ASPNET.aspx

    Thanks !

Comments have been disabled for this content.