Solved

Dataset not caching

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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…

685 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