当前位置: 首页 > news >正文

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 Sync ASync Processing request
  • 点评315:分众和中移动背后的故事
  • 中移动自建平台欲深度掌控产业链主导权
  • C# Asp.Net Set Image Url to byte[]
  • Google Android介绍..
  • “中关村装机”感受网店的力量
  • Oracle中锁定行的查找方法
  • svn删除仓库中某个目录的方法
  • 整合通讯录上“在乎网”
  • windows smartphone上几种java模拟器使用体验
  • OMA协议向导-一个帮助你了解OMA协议的简明教程(一)(二)
  • 美国百年老报关门将转型新闻网站
  • [创业] 读书推荐:创业者必读的《Founders at work: Stories of Startups' Early Days》
  • 中规中矩的新浪财报
  • NULL在SQLServer数据库日志文件中的存储
  • JS中 map, filter, some, every, forEach, for in, for of 用法总结
  • [数据结构]链表的实现在PHP中
  • 5、React组件事件详解
  • Angular js 常用指令ng-if、ng-class、ng-option、ng-value、ng-click是如何使用的?
  • avalon2.2的VM生成过程
  • co模块的前端实现
  • css选择器
  • Docker 1.12实践:Docker Service、Stack与分布式应用捆绑包
  • ERLANG 网工修炼笔记 ---- UDP
  • ESLint简单操作
  • HomeBrew常规使用教程
  • Iterator 和 for...of 循环
  • Laravel 中的一个后期静态绑定
  • Linux CTF 逆向入门
  • Map集合、散列表、红黑树介绍
  • MySQL-事务管理(基础)
  • niucms就是以城市为分割单位,在上面 小区/乡村/同城论坛+58+团购
  • Redis中的lru算法实现
  • vue脚手架vue-cli
  • zookeeper系列(七)实战分布式命名服务
  • 从0实现一个tiny react(三)生命周期
  • 看图轻松理解数据结构与算法系列(基于数组的栈)
  • 设计模式 开闭原则
  • 数据仓库的几种建模方法
  • 一个6年java程序员的工作感悟,写给还在迷茫的你
  • ​草莓熊python turtle绘图代码(玫瑰花版)附源代码
  • !! 2.对十份论文和报告中的关于OpenCV和Android NDK开发的总结
  • (16)Reactor的测试——响应式Spring的道法术器
  • (31)对象的克隆
  • (C语言)fgets与fputs函数详解
  • (html5)在移动端input输入搜索项后 输入法下面为什么不想百度那样出现前往? 而我的出现的是换行...
  • (Java)【深基9.例1】选举学生会
  • (Redis使用系列) SpringBoot中Redis的RedisConfig 二
  • (ZT)一个美国文科博士的YardLife
  • (读书笔记)Javascript高级程序设计---ECMAScript基础
  • (附源码)spring boot智能服药提醒app 毕业设计 102151
  • (五)c52学习之旅-静态数码管
  • (一)为什么要选择C++
  • .apk 成为历史!
  • .NET 4.0中使用内存映射文件实现进程通讯