Subscribe
to All!
Subscribe to
WMV.
Subscribe to
M4V (iPod).
Subscribe to
MP3.
Download WMV.
Download M4V (iPod).
Download MP3.
Show Notes:
- New Caching Support in .NET 3.5 SP1.
Source Code:
protected void
Page_Load(object sender, EventArgs e)
{
string Output = String.Empty;
if (!Page.IsPostBack)
{
lblOutput.Text =
GetCacheItem();
}
}
private string
GetCacheItem()
{
string OutValue = String.Empty;
if (Cache["Test"]
!= null)
{
OutValue = Convert.ToString(Cache["Test"]);
}
else
{
OutValue = DateTime.Now.ToString();
Cache.Insert("Test", OutValue, null,
DateTime.Now.AddSeconds(10),
TimeSpan.Zero,
OnUpdateCallback);
}
return (OutValue);
}
private void
OnUpdateCallback(String key, CacheItemUpdateReason r,
out Object
ObjectToCreate, out CacheDependency CacheDependencies,
out DateTime
DateTimeExpire, out TimeSpan TimeSpanExpire)
{
ObjectToCreate =
DateTime.Now;
CacheDependencies =
null;
DateTimeExpire =
DateTime.Now.AddSeconds(10);
TimeSpanExpire =
TimeSpan.Zero;
}