Solved

Dataset not caching

Posted on 2006-06-20
2
301 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

778 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