Variable loading of checkboxes from Caches

vaughnwhitehead
vaughnwhitehead used Ask the Experts™
on
Visual Studio 2017 ASP.net C#   -    

I have numerous checkboxes that are filled from a database.  When default page loads (and is not a postback) the lists are read from the database and placed into Caches.  

 Cache ACachce =  new Cache();
  ACachce.Insert(cacheName, ds, null, DateTime.Now.AddMinutes(10), Cache.NoSlidingExpiration,  CacheItemPriority.High, null);
  con.Dispose();
  return ds;    // a dataset


When I redirect to another page (not postback) the Caches are used to fill the checkboxes.   For example:  
if (chkChiefComplaint.DataSource == null)
       {
               chkChiefComplaint.DataSource = Cache["ChiefComplaint"];
               chkChiefComplaint.DataBind();
       }

Three other forms used the same checklists and read the Caches.  

My problem is that often (but not always) when redirecting to another page, the checkboxes are not filled.  If I return to the Default and then redirect back, the boxes are eventually filled, but it may take 2 to 3 rotations.    Once the boxes fill upon a page load they always filll  for any of the pages.  Sometimes the boxes fill correctly the first time a redirect is made.   The problem occurs in Chrome, IE, and Edge.   I have used try/catches to check for any errors.  

I do not know if it makes a difference, but these are Devexpress controls that are part of a Devexpress ASPX.FormLayout control.

I realize that this is a rather ambiguous problem, but any ideas or suggestions are greatly appreciated.

Vaughn Whitehead
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Chinmay PatelChief Technology Ninja
Distinguished Expert 2018

Commented:
Hi Vaughn,

1. Have you validated that cache are having these values filled in?
2. How are you making sure that someone is not overwriting the cache values? are these values unique for all users? Or cachename controls each unique user/group's checkbox settings?
3. Why are you expiring the values after 10 minutes? do you need to invalidate that frequently?

Regards,
Chinmay.

Author

Commented:
1. I check for errors while assigning the Cache values.  After each read from the database, I have set breakpoints and examined the datasets to make sure they contain the correct data.  

2. No one is overwriting as everything is still on local host.  I was under the impression that Cache values were accessed by all users, while Session values were per user.

3. The lists rarely change.  I chose 10 minute for no particular reason. First time I have used a Cache.  


Thanks

Vaughn
Problem was declaring the Cache as a local variable.  Moved the declaration into a Class and it works fine.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial