Asp.Net Cache
Asp.net Cache
Output Cache
Usage
·Cache all request: <%@ OutputCache Duration=”20” varybyparam =”none” %>
·<varybyparam= “*”>: will cache for each request with query string
·<varybyparam=”ProductId;ProductName”>: cache request with special query string
·Vary by custom:
a. <varybyparam=”none”varybycustom=”browser” >
b.in global.asax file:
public override string GetVaryByCustomString(HttpContext context, string tag){
if(tag==”browser”){ return context.Request.Browser.Browser;}
}
This will cache for different browser.
·Cacheby header :
<%@varybyparam =”none” varybyheader=”accept_product” %>
Scenario Example (varybyparam=”*”)
1.Request a page without parameter -> store page copy A
2.Request page pass Product id = 1 -> store page copy B
3.Request page Pass product id = 2 -> store page copy C
4.Request page Pass product id = 1 -> if copy B not expired , return copy B
5.Request page without parameter -> if copy A not expired , return copy A
Cache Profile and Configuration
Step 1:
<System.Web>
<Caching>
<OutputCacheSettings><OutputCacheProfiles>
<addname=”productCache” duration=”60”> -- seconds
</OutoutCacheProfiles></OutputCacheSettings></Cache></System.Web>
Step 2:
<%@OutputCache CacheProfile=”ProductCache” varybyparam=”none” %>
Cache Configuration
<System.Web><Caching><Cache
disableMemoryCollection=”true/false”– when memory is low need disable or not
disableExpiration=”true/false”
PercentagePhysicalMemoryUsedLimit=”90”—defaultis 90%
PrivateBytesLimit=”0”
privateBytesPoolTime=”00:2:00”
>
By default,Cache is stored in Cache Asp.net Process, so faster
For deploystrategy is not distribution system, suggest use this setting .
Distribute System Cache
1.Storein disk – suggest store in SSD for high speed I/O
2.SqlServer
3.Windowsserver App Fabric
Custom Cache
For some reason (Distribute system), need to build a custom Cache
1.Implement a Cache provider class by inherit from OutputCacheProvider
FileCacheProvider:OutputCacheProvider{
}
2.Config:
<System.Web><Caching><OutputCache defaultProvider=”FileCache”>
<Providers><add name =”FileCache” type=”FileCacheProvider”CachePath=”~/~” />
</Providers><…>
Or just override a method in global file :
Public override string GetOutputCacheProviderName(HttpContext context){
//implementation
}
Data Cache
Page Data Cache
Global toall requests
Thread safe
If expires,automatically remove
Can set dependence to a file or db object, once dependency object changes, cache will be removed automatically
Expiration policy
Sliding expiration: 10 min – if not used within 10 min, then remove
Absolution expiration:10 min – after 10min , remove
Code:
Slide Expiration:
Cache.Insert(“item”,obj,null, DateTime.Max, TimeSpan.FromMin(10));
Absolute Expiration:
Cache.Insert(“item”,obj,null, DateTime.Now.AddMin(60), TimeSpan.Zero);
Cache Dependency
File
Db Object
Message Queue
Cache dependencynotification
Sql server
1.sql server data table changed
2.affects a registered command
3.notification msg
Msmq
1.Cache object set dependency in MSMQ
2.Changes happen in MSMQ
3.Notify cache
Resource Cache
Cache by IIS .
相關文章
- ASP.NET CORE CACHE的使用(含MemoryCache,Redis)ASP.NETRedis
- Asp.net中cache管理機制介紹ASP.NET
- page cache與buffer cache的關係
- Guava CacheGuava
- Service Worker Cache 和 HTTP Cache 的區別HTTP
- cache buffers chains vs cache buffers lru chainAI
- cache buffers chains and cache buffers lru chainsAI
- Timesten新增Cache Groups到 Cache DatabaseDatabase
- MySQL:Table_open_cache_hits/Table_open_cache_misses/Table_open_cache_overflowsMySql
- PWA(Progressive Web App)入門系列:Cache Storage & CacheWebAPP
- How to Match a Row Cache Object Child Latch to its Row CacheObject
- buffer cache實驗5-latch:cache buffers chainAI
- Library Cache Pin 及 Library Cache Lock分析
- library cache lock和library cache pin理解
- 【Cache】將常用的“小表”快取到Buffer Cache快取
- MySQL Query CacheMySql
- Buffer Cache 原理
- cache buffer chainAI
- torrent cache websiteWeb
- Spring CacheSpring
- oracle library cache之library cache lock_library cache pin wait event釋義OracleAI
- mybatis原始碼學習------cache-ref和cache的解析MyBatis原始碼
- Service Worker cache 相比 HTTP cache 的一些優點HTTP
- Client Side Cache 和 Server Side Cache 的區別clientIDEServer
- 學習筆記:cache 和spring cache 技術(1)筆記Spring
- buffer cache實驗6-latch:cache buffers lru chainsAI
- 【構建Android快取模組】(二)Memory Cache & File CacheAndroid快取
- Metlink:How to Match a Row Cache Object Child Latch to its Row CacheObject
- iOS SDWebImgae Cache原理iOSWeb
- HTTP Cache 淺析HTTP
- oracle cache table(轉)Oracle
- Oracle Library cacheOracle
- Spring Cache 解析Spring
- Nginx配置fastcgi cacheNginxAST
- Nginx 配置 fastcgi cacheNginxAST
- Cache Aside PatternIDE
- Buffer Cache Hit Ratio
- 清理linux cacheLinux