Solved

Cached dropdownlist not consistent

Posted on 2008-10-29
8
245 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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 450 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now