Sign in
Code/Tea/Etc...
Duncan Mackenzie has too much time on his hands
Translate This Page
Translate this page
Powered by
Microsoft® Translator
Options
Blog Home
Email Blog Author
Share this
RSS for posts
Atom
RSS for comments
Search
Tags
.NET General
CSharp Featured Team Posts
Digital Music and Media
Pages
Personal Musings
TechEd
Visual Basic
Visual C#
Archive
Archives
September 2004
(1)
August 2004
(15)
July 2004
(27)
June 2004
(38)
May 2004
(34)
April 2004
(35)
March 2004
(33)
February 2004
(29)
January 2004
(23)
December 2003
(9)
November 2003
(46)
October 2003
(34)
September 2003
(13)
August 2003
(5)
July 2003
(14)
June 2003
(14)
May 2003
(22)
April 2003
(15)
March 2003
(23)
February 2003
(9)
Feeling the Cache Love
MSDN Blogs
>
Code/Tea/Etc...
>
Feeling the Cache Love
Feeling the Cache Love
Duncanma
6 Oct 2003 1:42 AM
Comments
5
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!
5 Comments
Visual Basic
,
.NET General
Blog - Comment List MSDN TechNet
Comments
Loading...