Solved

Dataset not caching

Posted on 2006-06-20
2
304 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
.NET Enums [Flags] & Bitwise Design Question 6 53
c# DateTime Format validation 4 93
How we can add Dten600.dll in GAC in c#. 18 55
asp.net repeater 2 38
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…
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

751 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