人生是一场不能存盘的RPG,我只能尽量多搞几个Screenshot

May 15, 2006

PetShop中的Facade

Filed under: 代码学习

在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.

Comments »

The URI to TrackBack this entry is: http://recordsome.blogsome.com/2006/05/15/p17/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.






















Get free blog up and running in minutes with Blogsome
Theme designed by Hadley Wickham