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

  • SEARCH
  • Home
  • 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 6005621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:25:23+00:00 2026-05-23T01:25:23+00:00

I have following scenario: Lets say we have two different webparts operating on the

  • 0

I have following scenario:

Lets say we have two different webparts operating on the same data – one is a pie chart, another is a data table.
in their Page_Load they asynchronously load data from the database and when loaded place it in application cache for further use or use by other web parts. So each o the web parts has code similar to this:

protected void Page_Load(object sender, EventArgs e)
    { 
       if (Cache["dtMine" + "_" + Session["UserID"].ToString()]==null)
       {
         ...
         Page.RegisterAsyncTask(new PageAsyncTask(
             new BeginEventHandler(BeginGetByUserID),
             new EndEventHandler(EndGetByUserID), 
             null, args, true));
       }
      else 
       {
         get data from cache and bind to controls of the webpart
       }
    }

Since both webparts operate on the same data it does not make sense for me to execute the code twice.

What is the best approach to have one web part communicate to the other “i am already fetching data so just wait until i place it in cache”?

I have been considering mutex, lock, assigning temporary value to the cache item and waiting until that temporary value changes… many options – which one should I use.

  • 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-23T01:25:24+00:00Added an answer on May 23, 2026 at 1:25 am

    You will want to take advantage of the lock keyword to make sure that the data is loaded and added to the cache in an atomic manner.

    Update:

    I modified the example to hold the lock accessing Cache for as short as possible. Instead of storing the data directly in the cache a proxy will be stored instead. The proxy will be created and added to the cache in an atomic manner. The proxy will then use its own locking to make sure that the data is only loaded once.

    protected void Page_Load(object sender, EventArgs e)
    { 
       string key = "dtMine" + "_" + Session["UserID"].ToString();
    
       DataProxy proxy = null;
    
       lock (Cache)
       {
         proxy = Cache[key];
         if (proxy == null)
         {
           proxy = new DataProxy();
           Cache[key] = proxy;
         }
       }
    
       object data = proxy.GetData();
    }
    
    private class DataProxy
    {
      private object data = null;
    
      public object GetData()
      {
        lock (this)
        {
          if (data == null)
          {
            data = LoadData(); // This is what actually loads the data.
          }
          return data;
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So lets say I have the following scenario. http://website.com:8080 and http://website.com:8080/demo Is there any
Lets say i have the following scenario: public class A { public String createString(final
Let's say I have the following scenario. A database of LocalLibrary with two tables
Lets say that I have the two following classes public class OtherClass { public
I am having following scenario: I have a table lets say X where fields
Following on from a previous question . Lets say I have two checkboxes on
The scenario is the following: Lets say I have this application App that depends
I have the following scenario: Entities are loaded from the database. One of them
I need to know the best approach for the following scenario lets say we
Lets say i have the following set of interfaces.... public interface IStart { void

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.