Caching for a single property or method in .NET.

Using VB.NET in this, in ASP.NET web forms.

I have a property that reads a list from a database by entity structure 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

Since this service requires database feedback, I would like to cache the results for future hits during one page life cycle (without ViewState). I know that 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 a way to use caching through an attribute to "automatically" cache the output of this property, without explicitly declaring, checking, and setting the cached object, as shown?

+3
source share
1 answer

, Aspect Oriented Programming. Castle Windsor PostSharp - . , .

, , , . , Castle, IL ( ).

, , . , , , .

+1

Source: https://habr.com/ru/post/1761226/


All Articles