惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

I
InfoQ
博客园_首页
美团技术团队
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
H
Help Net Security
J
Java Code Geeks
T
Tailwind CSS Blog
Jina AI
Jina AI
量子位
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
G
Google Developers Blog
爱范儿
爱范儿
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
宝玉的分享
宝玉的分享
小众软件
小众软件
MongoDB | Blog
MongoDB | Blog
博客园 - 三生石上(FineUI控件)
L
LangChain Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
V
Visual Studio Blog
博客园 - Franky
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

博客园 - Sunny

开发人员一定要加入收藏夹的网站(转载) 我写的一个小程序 tabs研究 dotnetnuke( modules /tabs )权限研究 数据库知识2 数据库学习1 可爱的外甥女 dotnetnuke 里profile 的使用 怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)? 编写upload程序 多国技术总结 远程教育系统总结 项目(多国技术) 总结 循环遍历一个控件方法 页面验证码程序(C#) string与stringbuilder flyweigth享元设计模式与委托总结 dotnetnuke 本地化技术杂谈 怎样获取获取GridView里面的label
asp.net缓存、企业程序库缓存及格式化日期 - Sunny - 博客园
Sunny · 2006-04-07 · via 博客园 - Sunny

格式化日期
<%#   string.Format("{0:yyyy-MM-dd}",DataBinder.Eval(Container.DataItem,"RoadGoodDate")   %>
<%#   DataBinder.Eval(Container.DataItem,"RoadGoodDate","{0:yyyy-MM-dd}")   %>

asp.net有页面缓存与API缓存及每请求缓存

页面缓存使用

<%@ OutputCache Duration="60" VaryByParam="*" %> 

API缓存
使用HttpRuntime.Cache.insert()    不返回值
HttpRuntime.Cache.Add()    返回cache引用,类型object

Call the Insert method, passing it an instance of the CacheDependency object 

The following code example adds an item named CacheItem3 that 
is dependent on another item in the cache named CacheItem2:

C#  Copy Code 
string[] dependencies = "CacheItem2" };
Cache.Insert(
"CacheItem3""Cached Item 3",
    
new System.Web.Caching.CacheDependency(null, dependencies));
 
The following code example shows an item named CacheItem4 added to the cache and having a file dependency 
set on the file named XMLFile.xml:

C#  Copy Code 
Cache.Insert(
"CacheItem4""Cached Item 4",
    
new System.Web.Caching.CacheDependency(
    Server.MapPath(
"XMLFile.xml")));
 
The following code example shows how to create multiple dependencies. It adds a key dependency on another item 
in the cache named CacheItem1 and a file dependency on the file named XMLFile.xml.

C#  Copy Code 
System.Web.Caching.CacheDependency dep1 
= 
    
new System.Web.Caching.CacheDependency(Server.MapPath("XMLFile.xml"));
string[] keyDependencies2 = "CacheItem1" };
System.Web.Caching.CacheDependency dep2 
= 
    
new System.Web.Caching.CacheDependency(null, keyDependencies2);
System.Web.Caching.AggregateCacheDependency aggDep 
= 
    
new System.Web.Caching.AggregateCacheDependency();
aggDep.Add(dep1);
aggDep.Add(dep2);
Cache.Insert(
"CacheItem5""Cached Item 5", aggDep);
 
Call the Insert method, passing it an absolute or sliding expiration time. 

The following code example adds an item to the cache with an absolute expiration of one minute:

C#  Copy Code 
Cache.Insert(
"CacheItem6""Cached Item 6",
    
null, DateTime.Now.AddMinutes(1d), 
    System.Web.Caching.Cache.NoSlidingExpiration);
 
Call the Insert method, specifying a value from the CacheItemPriority enumeration. 

The following code example adds an item to the cache with a priority value of High:

C#  Copy Code 
Cache.Insert(
"CacheItem8""Cached Item 8",
    
null, System.Web.Caching.Cache.NoAbsoluteExpiration,
    System.Web.Caching.Cache.NoSlidingExpiration,
    System.Web.Caching.CacheItemPriority.High, 
null);
 
Call the Add method, which returns an 
object representing the item. 

The following code example adds an item to the cache named CacheItem9 and sets the value of the variable CachedItem9 to be the item that was added.

C#  Copy Code 
string CachedItem9 = (string)Cache.Add("CacheItem9",
    
"Cached Item 9"null,
    System.Web.Caching.Cache.NoAbsoluteExpiration,
    System.Web.Caching.Cache.NoSlidingExpiration, 
    System.Web.Caching.CacheItemPriority.Default,
    
null);
 

每请求缓存则意味着只将数据缓存为该请求的持续时间。
使用HttpContext.Items["key"]=value   
items是一个属性,返回Idictionary类型,idictionary每一项为System.Collections.DictionaryEntry实体。

企业程序库:

配置web.config文件:

<cachingConfiguration defaultCacheManager="Default Cache Manager">
    
<backingStores>
      
<add name="inMemory" 
    type
="Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.NullBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching" />
    
</backingStores><cacheManagers>
      
<add name="Default Cache Manager"     
    expirationPollFrequencyInSeconds
="60"
    maximumElementsInCacheBeforeScavenging
="1000" 
    numberToRemoveWhenScavenging
="10"
    backingStoreName
="inMemory" />
      
<add name="Loading Scenario Cache Manager" 
    expirationPollFrequencyInSeconds
="60" 
    maximumElementsInCacheBeforeScavenging
="1000" 
    numberToRemoveWhenScavenging
="10"
    backingStoreName
="inMemory" />
    
</cacheManagers>
  
</cachingConfiguration>


添加dll引用,添加名字空间using Microsoft.Practices.EnterpriseLibrary.Caching;
使用如下代码:

            CacheManager cm = CacheFactory.GetCacheManager();
            QKnowledge qk 
= new QKnowledge(1"hi,catch");
            cm.Add(
"qk1", qk);
            QKnowledge qk1 
= (QKnowledge)cm.GetData("qk1");
            cm.Remove(
"qk1");