Solved

Dataset not caching

Posted on 2006-06-20
2
300 Views
Last Modified: 2010-04-16
Hi
can anyone help with these 2 problems.

1) Why will this not cache:

protected void Page_Load(object sender, EventArgs e)

{

DataSet CountryXMLFile = new DataSet();
        try
            {
            CountryXMLFile.ReadXml(Server.MapPath("countrylist.xml"));
            Cache.Insert("countrylist", CountryXMLFile, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero);
            }
        catch
            {
            return;
            }
        ddlCountry.DataSource = CountryXMLFile;
        ddlCountry.DataTextField = "Country";
        ddlCountry.DataValueField = "CountryID";
        ddlCountry.DataBind();
}

2) Put dataset into its own function

public ddlCountries()
{
DataSet CountryXMLFile = new DataSet();
        try
            {
            CountryXMLFile.ReadXml(Server.MapPath("countrylist.xml"));
            Cache.Insert("countrylist", CountryXMLFile, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero);
            }
        catch
            {
            return;
            }

}

protected void Page_Load(object sender, EventArgs e)

{
ddlCountry.DataSource = ddlCountries();
        ddlCountry.DataTextField = "Country";
        ddlCountry.DataValueField = "CountryID";
        ddlCountry.DataBind();
}

I've been trying for 2 days to solve these problem and I have decided I need help.
Regards
Caz
0
Comment
Question by:BeginningWebDesign
2 Comments
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 500 total points
ID: 16946138
Where are you "caching" ?

I see you adding it to the cache .. but you don't have valid code here .. and you never read from your cache?



try

public DataSet Countries() {
      if(!Cache.Contains("countrylist")) {
          CountryXMLFile.ReadXml(Server.MapPath("countrylist.xml"));
          Cache.Insert("countrylist", CountryXMLFile, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero);
      }
      return Cache["countrylist"];
}
0
 

Author Comment

by:BeginningWebDesign
ID: 16946358
Thanks gregoryyoung
Caz
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

14 Experts available now in Live!

Get 1:1 Help Now