PetShop中的Facade
在petshop中用到了HttpRuntime.Cache.Add()
其中第3个参数为dependencies,可以是null,说明此时无dependencie
petshop中的CacheDependency会根据web.confog来传递null,或dependencies
给HttpRuntime.Cache.Add()
这个变化被封装在DependencyFacade中
public static class DependencyFacade
{
private static readonly string path = ConfigurationManager.AppSettings[”CacheDependencyAssembly”];
//封装点
public static AggregateCacheDependency GetCategoryDependency()
{
if (!string.IsNullOrEmpty(path))
//这里又会用到Abstract Factory
return DependencyAccess.CreateCategoryDependency().GetDependency();
else
return null;
}
}
在使用时只会调用
// Create a AggregateCacheDependency object from the factory
AggregateCacheDependency cd = DependencyFacade.GetCategoryDependency();
// Store the output in the data cache, and Add the necessary AggregateCacheDependency object
HttpRuntime.Cache.Add(cacheKey, data, cd, DateTime.Now.AddHours(cacheDuration), Cache.NoSlidingExpiration, CacheItemPriority.High, null);
不用再判断何时需要传入null.
