Using VB.NET on this one, in ASP.NET Web Forms.
I have a property that reads a list from a database over the entity framework, as follows:
Public ReadOnly Property MyProperty As List(Of MyType)
Get
Using service As New MyDatabaseService
Return service.GetMyTypeList()
End Using
End Get
End Property
Because this service requires a round-trip to the database, I'd like to cache the results for future accesses during the same page lifecycle (no ViewState needed). I know this can be done as follows:
Private Property _myProperty As List(Of MyType)
Public ReadOnly Property MyProperty As List(Of MyType)
Get
If _myProperty Is Nothing Then
Using service As New MyDatabaseService
_myProperty = service.GetMyTypeList()
End Using
End If
Return _myProperty
End Get
End Property
Now for the question: is there any way to utilize caching via an attribute, to "automatically" cache the output of this property, without having to explicitly declare, test for, and set the cached object as shown?