How to invalidate a single data item in the .net cache in VB
Posted
by Craig
on Stack Overflow
See other posts from Stack Overflow
or by Craig
Published on 2010-06-03T11:14:02Z
Indexed on
2010/06/03
11:34 UTC
Read the original article
Hit count: 654
I have the following .NET VB code to set and read objects in cache on a per user basis (i.e. a bit like session)
'' Public Shared Sub CacheSet(ByVal Key As String, ByVal Value As Object) Dim userID As String = HttpContext.Current.User.Identity.Name
HttpContext.Current.Cache(Key & "_" & userID) = Value
End Sub
Public Shared Function CacheGet(ByVal Key As Object)
Dim returnData As Object = Nothing
Dim userID As String = HttpContext.Current.User.Identity.Name
returnData = HttpContext.Current.Cache(Key & "_" & userID)
Return returnData
End Function
I use these functions to hold user data that I don't want to access the DB for all the time. However, when the data is updated, I want the cached item to be removed so it get created again.
How do I make an Item I set disappear or set it to NOTHING or NULL?
Craig
© Stack Overflow or respective owner