Easy use of Caching
Steve Smith blogs about the "standard" way of accessing items in the cache.
I use this all the time. I usually do it like this so that you can access it like it as Property (but in VB.NET of course ;))
Public Shared ReadOnly Property MyData() As DataTable
Get
Dim Temp As DataTable = DirectCast(HttpContext.Current.Cache("MyData"), DataTable)
If Temp Is Nothing Then
Temp = GetData()
HttpContext.Current.Cache.Insert("MyData", Temp, Nothing, DateTime.Now.AddHours(1), TimeSpan.Zero)
End If
Return Temp
End Get
End Property
You could probably setup a macro to whip out these things pretty fast. This concept of encapsulating things into Properties also works great on appSettings items.
Public Shared ReadOnly Property MyProperty() As String
Get
Return ConfigurationSettings.AppSettings("MyProperty")
End Get
End Property
It might be kind of cool too, to see someone create a plug-in for Visual Studio .NET that would generate a class with a bunch of shared methods to reflect the settings in the web.config (or app.config) file every time you build your project. A new PowerToy? Maybe integrate it so it generates a "proxy class" for resources too? Anybody up for the challenge? ;)