I used this, still it "contacts" that server and doesnt use cache
<%@ Page Language="C#" Debug="true" %>
<%@OutputCache Duration="900" VaryByParam="none" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Xml" %>
<script runat="server">
void Page_Load(object sender, EventArgs e)
{
RssWeather.DataSource =
GetRSSFeed("
http://www.rssweather.com/rss.php?config=&forecast=zandh&place=p
hiladelphia+county&state=pa&zipcode=&country=us&county=42101&zone=PAZ071&alt
=rss20a");
RssWeather.DataBind();
}
private DataTable GetRSSFeed(string strURL)
{
DataSet ds = new DataSet();
ds.ReadXml(strURL);
return ds.Tables[2];
}
</script>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<asp
ataGrid id="RssWeather" Width="100%"
AlternatingItemStyle-BackColor="#eeeeee" HeaderStyle-Font-Size="12pt"
HeaderStyle-ForeColor="White" HeaderStyle-BackColor="Navy"
HeaderStyle-HorizontalAlign="Center" HeaderStyle-Font-Bold="True"
Font-Size="8pt" Font-Name="Arial" AutoGenerateColumns="false"
runat="server">
<Columns>
<asp:TemplateColumn HeaderText="Weather Forecast -
Philadelphia
County">
<ItemTemplate>
<b><%# DataBinder.Eval(Container.DataItem, "title")
%></b><br/>
<%# DataBinder.Eval(Container.DataItem, "description") %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp
ataGrid>
</body>
</html>
In VB and untested (sorry)...
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
BindGrid()
End If
End Sub
Private Sub BindGrid()
Dim dsWeather As DataSet = CType(Cache.Get("WeatherCache"),
DataSet)
If dsWeather Is Nothing Then
'Response.Write("<b>Dynamically Created</b><p>")
dsWeather =
GetRSSFeed("
http://www.rssweather.com/rss.php?config=&forecast=zandh&place=p
hiladelphia+county&state=pa&zipcode=&country=us&county=42101&zone=PAZ071&alt
=rss20a")
' refreshes dataset if 61 minutes goes by since cached
Cache.Insert("WeatherCache", dsWeather, Nothing,
DateTime.Now.AddMinutes(61), Cache.NoSlidingExpiration)
Dim dv As New DataView(dsWeather.Tables(0))
RssWeather.DataSource = dv
RssWeather.DataBind()
Else
'Response.Write("<b>From Cache</b><p>")
Dim dv As New DataView(dsWeather.Tables(0))
RssWeather.DataSource = dv
RssWeather.DataBind()
End If
End Sub
Greg
Greg,
how do i put caching on and set it to like 61 minutes?
I started with .net yesterday so i have no clue lol
here is my code:
<%@ Page Language="C#" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Xml" %>
<script runat="server">
void Page_Load(object sender, EventArgs e)
{
RssWeather.DataSource =
GetRSSFeed("
http://www.rssweather.com/rss.php?config=&forecast=zandh&place=p
hiladelphia+county&state=pa&zipcode=&country=us&county=42101&zone=PAZ071&alt
=rss20a");
RssWeather.DataBind();
}
private DataTable GetRSSFeed(string strURL)
{
DataSet ds = new DataSet();
ds.ReadXml(strURL);
return ds.Tables[2];
}
</script>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<asp
ataGrid id="RssWeather" Width="100%"
AlternatingItemStyle-BackColor="#eeeeee" HeaderStyle-Font-Size="12pt"
HeaderStyle-ForeColor="White" HeaderStyle-BackColor="Navy"
HeaderStyle-HorizontalAlign="Center" HeaderStyle-Font-Bold="True"
Font-Size="8pt" Font-Name="Arial" AutoGenerateColumns="false"
runat="server">
<Columns>
<asp:TemplateColumn HeaderText="Weather Forecast">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "title")
%><br/>
<%# DataBinder.Eval(Container.DataItem, "description") %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp
ataGrid>
</body>
</html>
Sounds like a good use for the Cache object. When you first load it
shove
it
in Cache object and set an expiration of 1 hour. On every page load
check
to see if Cache object is nothing, if it is then hour should be up
so
reload
it...
Greg
Hello
I was wondering how to solve this issue....
I have a weather RSS that i retrieve xml from..... and it only
allows
me
to
get data once each hour, so if i reload my page i get an error,
how
to
resolve that?
TIA
/Lasse