Solved

Dataset not caching

Posted on 2006-06-20
2
299 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
Comment Utility
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
Comment Utility
Thanks gregoryyoung
Caz
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 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

12 Experts available now in Live!

Get 1:1 Help Now