Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Cached dropdownlist not consistent

Posted on 2008-10-29
8
Medium Priority
?
252 Views
Last Modified: 2013-12-17
Ive got a basic aspx page that loads a dropdown with employee names.  Since this data rarely changes, and since its around 6,000 names, I decided to cache the data using the code in the snippet.  My problem is that sometimes the dropdown has data..and sometimes it doesnt.  If I start a debug session and the dropdown is not filled, I can usually wait a minute or two then start the debugger back up and it will then be filled.  Why would it sometimes have data and other times be empty?  
if (Cache["employees"] == null)
            {
                DataTable dt = new DataTable();
                dt = employees.GetEmployees();
                Cache.Insert("employees", dt, null, DateTime.Now.AddMinutes(480), TimeSpan.Zero);
            }
 
            ddlEmployee.DataSource = (DataTable)Cache.Get("employees");
            ddlEmployee.DataTextField = "name";
            ddlEmployee.DataValueField = "emplid";
            ddlEmployee.DataBind();

Open in new window

0
Comment
Question by:clintfield
  • 3
  • 3
8 Comments
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 22906900
Hi clintfield,
May i know why you need to cache the data before output the resouces? It's not adviceable to use Cache in somehow. Please refer following articles for more details regarding Cache usage. Please check if you really need to use Cache in the existing code:
You may need to check why Cache object display inconsistenly for some reason:
Caching time and expiration:
http://ajdotnet.wordpress.com/2006/10/18/cache-as-cache-can/

0
 
LVL 1

Author Comment

by:clintfield
ID: 22906997
I could rewrite the code to supply the dropdown and then cache.  The real problem is that the dropdown sometimes doesnt have any data, even though it should have been cached.  I cached this particular dropdown because it contains a massive amount of names (I rechecked and there are actually 40,000+ names!) and it rarely changes.  It is also called regularly and sometimes more than once on the same page.
0
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 22907130
Hi clintfield,
That is too huge data for dropdownlist's resource. Perhaps you can try with other way instead of bind too large data in the dropdownlist. You can try use an AutoCompleteExtender instead.
http://forums.asp.net/t/1266932.aspx
 
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:clintfield
ID: 22907288
That looks sweet....but my company hasnt certified the toolkit yet so I cant use that.  ;-(
0
 
LVL 29

Accepted Solution

by:
David H.H.Lee earned 1800 total points
ID: 22907456
Hi clintfield,
Then you can let them know how good it is compare with old solution. There are a lot of useful controls available for AJAX toolkit:
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/AutoComplete/AutoComplete.aspx
Good luck to your project.

0
 
LVL 1

Author Comment

by:clintfield
ID: 22907468
Thanks for the ideas.
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question