The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Feeling the Cache Love

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Duncan Mackenzie

Posts: 689
Nickname: duncanma
Registered: Aug, 2003

Duncan Mackenzie is the Visual Basic Content Strategist at msdn.microsoft.com
Feeling the Cache Love Posted: Oct 6, 2003 3:21 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Duncan Mackenzie.
Original Post: Feeling the Cache Love
Feed Title: Code/Tea/Etc...
Feed URL: /msdnerror.htm?aspxerrorpath=/duncanma/rss.aspx
Feed Description: Duncan is the Visual Basic Content Strategist at MSDN, the editor of the Visual Basic Developer Center (http://msdn.microsoft.com/vbasic), and the author of the "Coding 4 Fun" column on MSDN (http://msdn.microsoft.com/vbasic/using/columns/code4fun/default.aspx). While typically Visual Basic focused, his blogs sometimes wanders off of the technical path and into various musing of his troubled mind.
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Duncan Mackenzie
Latest Posts From Code/Tea/Etc...

Advertisement
I've been working on the business and data layers for a web system and, as you might expect, I've been making quite a bit of use of ASP.NET's caching system. Now, to test the business layer, I had gone ahead and set up a non-ASP.NET caching system as well using my standard method for caching in Windows applications, a static hashtable with strongly typed string keys (works well, fairly compatible with the ASP.NET cache so it is easy to move code between the two models) but then I realized that I could just use the ASP.NET cache even when my code was being used from a Windows Forms applications (for my class libraries, where I don't know what type of interface is being used) and it works just fine.


Shared Function GetValueFromCache( _
        ByVal key As String) As Object
    Dim myContext As HttpContext
    myContext = HttpContext.Current

    If myContext Is Nothing Then
        Return HttpRuntime.Cache.Get(key)
    Else
        Return myContext.Cache.Get(key)
    End If
End Function

Shared Sub PlaceValueIntoCache( _
    ByVal key As String, _
    ByVal item As Object, _
    ByVal cacheDuration As Integer)
    Dim myContext As HttpContext
    myContext = HttpContext.Current
    Dim myCache As Caching.Cache

    If myContext Is Nothing Then
        myCache = HttpRuntime.Cache
    Else
        myCache = myContext.Cache
    End If

    myCache.Insert(key, item, Nothing, _
    Now.AddSeconds(cacheDuration), _
    Caching.Cache.NoSlidingExpiration)
End Sub


This might be common knowledge, but I have been handling my own non-ASP.NET caching all on my own, and this just makes it too easy. In fact, it makes it so easy that I started thinking of ways to perform even more caching in some of my Windows Forms applications... I can see many performance gains in my future!

Read: Feeling the Cache Love

Topic: .NET Nightly 21 Previous Topic   Next Topic Topic: Avanade Bloggers

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use