Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1009057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:52:01+00:00 2026-05-16T08:52:01+00:00

Using VB.NET on this one, in ASP.NET Web Forms. I have a property that

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:52:02+00:00Added an answer on May 16, 2026 at 8:52 am

    The answer is sort of, but you will need to use Aspect Oriented Programming techniques in order to achieve this. Castle Windsor or PostSharp are two excellent .net frameworks that can help get you there, but this is not a light subject by any means.

    Basically AOP involves wrapping up common boilerplate functionality into aspects that can be used to decorate code, leaving only the essence of what you want. This can be done dynamically at runtime as Castle does, or at compile time by IL weaving (dynamically compiling the new code into your assembly).

    Each approach has its strengths and weaknesses, but I urge you to research the topic as it spans further than just caching. Many common tasks such as exception handling and logging can easily be refactored into aspects to make your code extra clean.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an ASP.NET page, using VB.NET and I have this hierarchy: Page
My current position is this: if I thoroughly test my ASP.NET applications using web
I have been using asp.net programming just from few months and I have to
Using asp.net MVC I'd like to do this inside a view: <%= Html.TextBox(textbox1, null,
Using VB.net (.net 2.0) I have a string in this format: record1_field1,record1_field2,record2_field3,record2_field1,record2_field2, etc... I
I know this site is written using ASP.Net MVC and I do not see
I'm using Lucene.Net in an ASP.NET application on a shared host. Got this stack
I am using ASP.NET to transmit a .jar file. This code works perfectly on
I'm using a ASP.NET menu control. I'd like the menu to look like this,
Using a technique I found in one of the recent ASP.NET MVC books, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.