
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
810
|
Chapter 14: Web
using (SqlConnection sqlConn = new SqlConnection(connStr))
{
using (SqlDataAdapter adapter =
new SqlDataAdapter("SELECT * FROM AUTHORS", sqlConn))
{
adapter.Fill(authorInfo);
// Now add the royalty info.
authorInfo.ReadXml(file, XmlReadMode.InferSchema);
Finally, an AggregateCacheDependency is created for the DataSet from the CacheDependency
(fileDep)
and the SqlCacheDependency (sqlDep). The DataSet is added to the cache
with the
AggregateCacheDependency (aggDep) and the cache takes care of managing
the DataSet from this point forward. If a DataSet is in the cache already and the
dependencies have not been triggered, the
DataSet from the cache is returned.
// Make the aggregate dependency so that if either the
// db or file changes, we toss this out of the cache.
AggregateCacheDependency aggDep = new AggregateCacheDependency( );
// Add the two dependencies to the aggregate.
aggDep.Add(new CacheDependency[] { sqlDep, fileDep });
// Add author info dataset to cache with the aggregate
// dependency so that if either changes the cache will refetch.
this.Cache.Insert("authorInfo", authorInfo, aggDep);
}
}
}
else
{
authorInfo = (DataSet)this.Cache["authorInfo"];
}
Discussion
The AggregateCacheDependency class is new in the 2.0 Framework, and it is a wel-
come addition ...