ASP.NET has a very good asynchronous programming model that uses the CacheItemRemovedCallback delegate to inform the application when a cache item is expired and helps the developer to write code to retrieve it.
public delegate void CacheItemRemovedCallback(string key, object value, CacheItemRemovedReason reason);
public class User
{
public Int32 ID { get; set; }
public String Name { get; set; }
}
public class Details
{
public User User { get; set; }
public Int32 Extension { get; set; }
public String Project { get; set; }
}
User parent = new User { Name = "Me", ID = 1 };
Details child = new Details {User = parent, Project = "My Project", Extension = 555 };
Cache.Insert("Parent", parent);
CacheDependency dependency = new CacheDependency(null, new String[] { " Parent" });
Insert child object and add a CacheItemRemovedCallback delegate.
Cache.Insert(
"Child",
child,
dependency,
DateTime.Now.AddHours(30),
TimeSpan.Zero,
CacheItemPriority.Normal,
new CacheItemRemovedCallback(
delegate(String key, Object value, CacheItemRemovedReason reason)
{
if(reason == CacheItemRemovedReason.DependencyChanged)
//Use AJAX/ events here if required.
Cache.Insert(key, new Details { User = null, Extension = default(Int32), Project = String.Empty });
})
);
No comments:
Post a Comment