企业库系列讲座:缓存应用程序块.ppt

上传人:xt****7 文档编号:5176045 上传时间:2020-01-22 格式:PPT 页数:49 大小:2.85MB
返回 下载 相关 举报
企业库系列讲座:缓存应用程序块.ppt_第1页
第1页 / 共49页
企业库系列讲座:缓存应用程序块.ppt_第2页
第2页 / 共49页
企业库系列讲座:缓存应用程序块.ppt_第3页
第3页 / 共49页
点击查看更多>>
资源描述
November2004 EnterpriseLibraryCachingApplicationBlock 莫淘ArchitectEvangelistDevelop PlatformEvangelismMicrosoft China November2004 温故 知新 什么是Patterns practicesApplicationBlock的发展 November2004 Patterns practicesArchitectureGuidancefortheEnterprise ReferenceArchitectures ApplicationBlocks GuidesGuidanceforbroadhorizontaltopicssuchassecurity performance deploymentandoperations Patterns D A D I A D I Atomicsolutionstorecurringproblems Sub system levelguidanceforcommonservices System levelguidanceforcommoncustomerscenarios D A D I A D I Availableonline ProvenBasedonfieldexperienceAuthoritativeOfferthebestadviceavailableAccurateTechnicallyvalidatedandtestedActionableProvidethestepstosuccessRelevantAddressreal worldproblemsbasedoncustomerscenarios Factory Plugin Enterpriselibrary Indigo November2004 AppBlockHistory Feedback 发展历史 History 应用程序块 Applicationblocks 已经诞生多年在Microsoft内部 程序块产生在不同的设计组中 并演化了多年程序块涉及的范围verysimplehelperspowerfulframeworkslikeUIP几点共识降低项目成本增加解决方案的可用性业界反馈 Feedback 提供了程序块的一致性提供了模块之间更少的依赖性OnotherblocksOninfrastructure更容易的配置易用性 November2004 Security Crypto Configuration DataAccess Logging Caching Exceptions EnterpriseLibraryv1总体架构 Legend Dependency Plug in ConfigTool November2004 EnterpriseLibraryVision Partnerblocks Customerblocks Communityblocks p pblocks BlockSpecification November2004 EnterpriseLibrary的定义 EnterpriseLibrary是 是面对一些企业级应用开发中常见的问题的解决方案库 libraryofapplicationblockswhichsolvecommonchallenges 是一系列可以工作在任何架构下的帮助类 Asetofhelperclasseswhichworkinanyarchitecturalstyle 是体系架构上的指导性文件 Architecturalguidanceembodiedincodewhichshipswithfullsourceallowingyoutomodifyandextend 是免费的 Availableasafreedownload EnterpriseLibrary不是 不是 Net架构中的一部分 Apartofthe NETFramework 不对任何体系架构后依赖或影响关系 Anapplicationframeworkthatimposesanarchitecturalstyle 不是一种官方支持的产品 AMicrosoftproductwithsupport compatibilityandlocalization 不用于销售 Forsale November2004 Enterprise的未来之路 微软将一如既往的在改领域进行投入 Wewillcontinuetoinvestinblocksandblocklibraries 将不断的扩展 升级该方案库 Additionalcapabilitiesandscenarios Newblocks suchasValidationUpdatingexistingapplicationblocks suchasUIPScenariossuchasSmartClient融入其他的产品 Enablement VisualStudiotoolingandwizardsDeepercommunitypenetration会出现在新的 NET2 0 Whidbey上的方案BlocksrevvedtoadheretobestpracticesofnewplatformIntegrationwithnewVS2005experiences November2004 今天的交流题目 Patterns practices中关于缓冲的指导意见关于CachingApplicationBlock应用场景和设计指南的描述应用示例问题解答 November2004 有同感 用户抱怨系统的性能您已经将明年的预算花在如何扩展现有的数据库服务器的吞吐能力上了您的应用程序在没有和后端的数据源连接时 程序不能够执行或执行的很不好 November2004 为什么需要Cache 性能采用一种更为密切的方式 为数据的消费者存储相关的数据 以避免重复性的数据创建 处理和传输 可扩展性避免在相同的数据处理和业务逻辑上浪费资源 减小数据库的请求 以便允许更多的客户访问 可用性在另外的地方存储数据 您的应用能够在网络的的延时 WEB服务和硬件的问题中减小损失 November2004 典型的应用场景 提问 以前不是有缓冲吗 System Web Cache回答 全面性 易用性 一致性 您正在使用本地的缓冲创建智能客户端应用使用缓冲功能 支持离线应用您正在创建WINDOWS服务或者控制台应用 并且需要使用缓冲改善性能 November2004 什么是缓冲应用程序块 提供了一些方便易用的 可扩展的缓冲机制 这些缓冲机制可以使用在整体应用中的各个层面 支持后期存储 支持的存储方式包括数据库方式和独立存储方式 Isolatedstorage 便于应用方便的重新启动便于使用便于配置支持使用配置工具线程安全可以确保在内存中的缓冲和后端存储保持同步 November2004 深入了解缓冲模块 如何创建缓冲配置文件选择后端存储创建缓冲向缓冲中添加一项设置过期策略从缓冲中获得一项内容缓冲装载策略从缓冲中移除一项刷新缓冲关键特性 November2004 Security Crypto Configuration DataAccess Logging Caching Exceptions CacheAB所处的地位 Legend Dependency Plug in ConfigTool November2004 在您的应用配置文件中增加一个缓冲应用为要创建的数据项创建Cachemanager每一个子项需要有独立的名字确定哪一个是默认的Cachemanager 创建配置文件 November2004 关于缓冲存储的几点建议 内存驻留型缓冲的典型应用 应用程序经常使用同样的数据一个应用程序经常需要重新获得数据磁盘驻留型缓冲的典型应用 数据量比较大同时 从应用服务提供商 例如数据库 重新获取数据 开销比较大在缓冲的生命周期中 必须经历系统的重新启动 CachingArchitectureGuidefor NETFrameworkApplications November2004 缓冲通常在内存中还经常需要有后端存储没有后端存储 是不容易实现持久化的因此持久化存储是非常必要的持久化的后端存储当需要被缓冲的数据的生命周期中不可避免的需要经历进程或系统的重启时支持使用隔离式存储和数据库方式 DataAccessApplicationBlock 内容需要和缓冲一致 Rollback 内容是从缓冲的初始化时装载到后端的 关于缓冲存储的几点建议 2 November2004 关于缓冲存储的几点建议 3 隔离式存储支持基于用户和程序集的隔离机制不需要UniquePath了避免HardCodeCachingApplicationBlock提供了分区机制 在一个应用程序中 并存多个cachemanagers不支持 也不应该支持多个由多个Cachemanager共享存储或分区 November2004 关于缓冲存储配置 缓冲还要加密 内存溢出 木马程序 DataAccessApplicationBlock利用数据库实例进行分区的命名和数据的分离需要数据库访问模块 DAAB 的支持 November2004 如何加密 需要CryptographyApplicationBlock模块的支持应该使用对称算法 关于缓冲存储配置 2 November2004 创建默认cachemanager 典型用法 CacheManagermyCache CacheManager GetCacheManager 创建命名的cachemanager CacheManagerproductsCache CacheManager GetCacheManager Products November2004 增加条目 默认的增加一个条目 productsCache Add ProductID123 productObject 默认值清除优先级 Normal过期设置 Noexpiration注意增加第二个同样KEY值的条目 会替换掉第一个当希望使用后端存储时 对象应该支持序列化 November2004 定义过期策略 基于时间的过期设置过期时间支持两种 相对时间绝对时间对于使用那些变化比较大的数据 例如经常被更新的数据或只在一段时间内存在的数据时 建议存在在缓冲中基于提醒的过期 且支持策略对该资源属性的更改 对应的提醒 Suchasafile afolder oranyothertypeofdatasource 只是Remove November2004 基于时间的过期 绝对时间 Absolute 允许您定义缓冲项的生命周期简单的方法 指定一个特定的时间作为过期扩展方法 您可以通过表达式定义EveryminuteEverySunday15thofEverymonth 变化的时间允许您定义针对条目的被调用的两次之间的间隔 定义条目的生命周期 November2004 基于时间的实例 DateTimerefreshTime newDateTime 2005 3 21 2 0 0 AbsoluteTimeexpireTime newAbsoluteTime refreshTime primitivesCache Add Key1 CacheItem1 CacheItemPriority Normal null expireTime 需要使用ADD方法CachingApplicationBlock支持基于时间的表达式AbsoluteTimeSlidingTimeExtendedFormatTime例如 expireat2 00AMon3 21 05 November2004 变化时间的过期 TimeSpanrefreshTime newTimeSpan 0 5 0 SlidingTimeexpireTime newSlidingTime refreshTime primitivesCache Add Key1 CacheItem1 CacheItemPriority Normal null expireTime 例如 被访问5分钟后 November2004 支持的时间表达方法和示例 Extendedtimeformat meansruneveryperiodExamples expireseveryminute 5 expire5thminuteofeveryhour 21 expireeveryminuteofthe21sthourofeveryday 3115 expire3 31PMeveryday 74 6 expireSaturday4 07AM 152147 expire9 15PMon4July November2004 扩展时间应用范例 ExtendedFormatTimeexpireTime newExtendedFormatTime 00 6 primitivesCache Add Key1 CacheItem1 CacheItemPriority Normal null expireTime 扩展时间应用范例 expireatmidnighteverySaturday November2004 基于提醒机制的过期 FileDependencyexpireNotice newFileDependency Trigger txt productsCache Add Key1 CacheItem1 CacheItemPriority Normal null expireNotice 文件依赖的例子 expireifthefileTrigger txtischanged 您可以创建自己的过期类 只需要实现ICacheItemExpiration接口 November2004 配置过期表决的频率 通过后台线程 BackgroundScheduler 移除过期事项您可以对次线程进行配置过高 CPU浪费 且CACHE没有起到作用过低 内存消耗太大建议使用性能计数器监视一下 November2004 条目移除提示 productsCache Add Key1 CacheItem1 CacheItemPriority Normal newProductCacheRefreshAction expireNotice CachingApplicationBlock提供了项目移除的提醒 并在一下情况下被激活条目过期了条目被显式的移除了条目被策略的清楚了需要实现ICacheItemRefreshAction接口 November2004 条目移除提示 2 Serializable publicclassProductCacheRefreshAction ICacheItemRefreshAction publicvoidRefresh stringkey objectexpiredValue CacheItemRemovedReasonremovalReason Itemhasbeenremovedfromcache Performdesiredactionshere basedupontheremovalreason e g refreshthecachewiththe item 一个类实现了ICacheItemRefreshAction接口 同时如果需要后端存储时 还必须被标识为Serializable Especiallyforpersistentbackingstore November2004 类型要正确一定要检查空值 itemnotfoundincache 从Cachemanager中获取 publicProductReadProductByID stringproductID Productproduct Product cache GetData productID if product null Itemnotincache 类型转换 检查空值 November2004 装载缓冲 缓冲的前期装载 Proactiveloading 应用启动时装载优点全部装载后 应用运行性能提升明显缺点启动时间长可能带来不必要的资源浪费为了提升启动性能而进行的 基于不同线程的装载 有造成了应用结构的复杂性缓冲的被动装载 Reactiveloading 按需装载优点只有在需要的时候才装载 对资源的需求小缺点但是在首次装载的时候 速度慢 November2004 1 Createcachemanager 主动装载的实例 CacheManagerproductsCache CacheManager GetCacheManager RetrievethedatafromthesourceArrayListlist dataProvider GetProductList Addalltheitemstothecachefor inti 0 i list Count i Productproduct Product list i productsCache Add product ProductID product 2 Additemsduringcomponentinitialization November2004 后期装载的实例 Productproduct Product productsCache GetData productID if product null Retrieveitfromthedataprovider andcacheitformorerequests product dataProvider GetProductByID productID if product null productsCache Add productID product 1 Createcachemanager CacheManagerproductsCache CacheManager GetCacheManager 2 Additemswhenretrievedfromdatasource November2004 何时使用主动装载 Proactivecaching 在一些情况下中 他们自己有更新周期 当装载到缓冲将导致状态过期的出现 Youareusingstaticorsemistaticstatethathasknownupdateperiods Ifyouuseitinotherscenarios thestatemightexpirebeforeitisused 此时 您需要清楚的知道被缓冲的对象的生命周期 Youareusingstatewithaknownlifetime您还需要提前知道占用资源的程度 Youareusingstateofaknownsize Ifyouuseproactivecachedataloadingwhenyoudonotknowthesizeofthedata youmightexhaustsystemresources Youmusttrytonotuseresourcesthatyoudonothave 使用不稳定的资源时 尽量多使用主动装载缓冲 Youhaveproblematicresources suchasaslowdatabase aslownetwork orunreliableWebservices Youcanusethistechniquetoretrieveallthestateproactively cacheit andworkagainstthecacheasmuchasitcan 最佳实践 Cache主动装载 November2004 何时使用被动装载 需要缓冲的对象状态过多或系统资源不足的情况 Youareusinglotsofstateandyoudonothavesufficientresourcestocacheallstatefortheentireapplication 资源的可靠性和性能良好 此时被动装载的又是更明显 Youareusingreliableandresponsiveresources suchasadatabase network orWebservicethatwillnotimpedeapplicationstabilityandperformance 希望利用缓冲机制 但是在应用程序的初始化时 希望不使用缓冲 而是根据用户输入等条件 进行缓冲 Youareinterestedincachingdatathatisnotavailableduringtheinitializationofanapplication Forexample thisdatamightbeaffectedbyuserinputsuchascommonsearchqueriesoruser specificdatasuchasauser sprofile 最佳实践 Cache被动装载 November2004 1 Removeitemwithspecifiedkey 从缓冲中移除 productsCache Remove Product101Key 2 Noerroroccursifkeyisnotfound因此通过这种方法 不能知道ITEM是否移除了如果对象实现了ICacheRefreshItemAction 可以有信息 November2004 刷新缓冲 为了更有效的利用资源 您需要刷新缓冲 Usetomanagestorage memoryandotherresourcesefficiently精确刷新 Explicitflushing使用代码 Initiatedbyapplicationcode全部移除 Removesallitemsfromthecache自我清除 Scavenging使用应用程序块的功能 Initiatedbyapplicationblock基于优先级和最后访问的时间 Baseduponpriorityandlastaccesstime控制移除的精确度 Configurationsettingscontrolsizeofcacheandnumberremoved productsCache Flush November2004 自我清除 1 自我清除的配置缓冲中的最大元素数量 Maximumelementsincache一次移除的数量 Numberofitemsremovedwhenscavengingoccurs November2004 自我清除 2 为缓冲建立优先级 productsCache Add Key1 CacheItem1 CacheItemPriority High newProductCacheRefreshAction expireNotice 优先级的值LowNormalHighNotRemovable自我清除的算法 不需要扩展 View ApplicationShare Demonstration LiveMeetingView ApplicationShare UseLiveMeeting EditSlideProperties toedit November2004 再次重复几个关键点 1 支持客户化后端存储 Backingstoreprovider ImplementIBackingStore derivefromBaseBackingStore UseConfigurationConsoletoselectcustomprovider支持客户化过期策略ExpirationpolicyImplementICacheItemExpirationSpecifyobjectoncalltoAddmethodofCacheManagerobject另外 Anythingandeverything youhavethesourcecode Pleasepostextensionsandsuggestionstothecommunity November2004 Security Crypto Configuration DataAccess Logging Caching Exceptions 再次重复几个关键点 2 Legend Dependency Plug in ConfigTool Announcing EnterpriseLibrary1 0 DownloaditToday November2004 patterns practicesLive 2005 6 7EnterpriseLibraryLogging InstrumentationApplicationBlock2005 6 7EnterpriseLibraryExceptionHandlingApplicationBlock2005 6 7EnterpriseLibraryCryptographyApplicationBlock2005 6 7BuildyourownEnterpriseLibraryApplicationBlock EnterpriseLibraryCommunity
展开阅读全文
相关资源
相关搜索

当前位置:首页 > 图纸专区 > 课件教案


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!