新足迹

 找回密码
 注册

精华好帖回顾

· 我买房了(在堪培拉)填坑完毕 (2009-2-11) distantmusic · 春天的蓝花楹 (2017-5-30) Alicefowley
· 山寨八宝饭 (2010-1-4) 高寿财 · 近日小菜-生炸云吞、K三文鱼汤、手工大肉包、香菇腐竹炖大肉、肉燥卤蛋、凉拌牛舌 (2007-7-2) 豆豆猫
Advertisement
Advertisement
查看: 1429|回复: 11

ASP.net Caching 初级问题。 [复制链接]

头像被屏蔽

禁止发言

发表于 2011-1-7 11:13 |显示全部楼层
此文章由 澳贼 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 澳贼 所有!转贴必须注明作者、出处和本声明,并保持内容完整
如何 让 Caching 在某一特定时间expire??

我们的新数据每天早上更新。
Advertisement
Advertisement
头像被屏蔽

禁止发言

发表于 2011-1-7 11:20 |显示全部楼层

双胸何在?

此文章由 澳贼 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 澳贼 所有!转贴必须注明作者、出处和本声明,并保持内容完整

发表于 2011-1-7 11:34 |显示全部楼层
此文章由 乱码 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 乱码 所有!转贴必须注明作者、出处和本声明,并保持内容完整
你加一个dependency就好啊,不用设datetime,你具体看看它的api吧

Cache.Insert(key as String, value as Object, dependencies as CacheDependency, absoluteExpiration as DateTime, slidingExpiration as TimeSpan)
头像被屏蔽

禁止发言

发表于 2011-1-7 11:40 |显示全部楼层
此文章由 澳贼 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 澳贼 所有!转贴必须注明作者、出处和本声明,并保持内容完整
http://msdn.microsoft.com/en-us/ ... itemremovedcallback(v=VS.90).aspx

想好了,只要算出时间就可以了。


原帖由 乱码 于 2011-1-7 11:34 发表
你加一个dependency就好啊,不用设datetime,你具体看看它的api吧

Cache.Insert(key as String, value as Object, dependencies as CacheDependency, absoluteExpiration as DateTime, slidingExpiration as TimeSpan ...
签名被屏蔽

发表于 2011-1-7 11:50 |显示全部楼层
此文章由 乱码 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 乱码 所有!转贴必须注明作者、出处和本声明,并保持内容完整
原帖由 澳贼 于 2011-1-7 11:40 发表
http://msdn.microsoft.com/en-us/ ... itemremovedcallback(v=VS.90).aspx

想好了,只要算出时间就可以了。




嗯,如果dependency太麻烦,这是最好的solution,skip掉date,只考虑hour/minute/sec就好.
头像被屏蔽

禁止发言

发表于 2011-1-7 11:53 |显示全部楼层

比如说 11:15AM

此文章由 澳贼 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 澳贼 所有!转贴必须注明作者、出处和本声明,并保持内容完整
Cache.Insert("Key", GetObject(), null, DateTime.Today.AddHours(11.25d), Cache.NoSlidingExpiration, CacheItemPriority.Default,
                    new CacheItemRemovedCallback(RefreshCache));
Advertisement
Advertisement

2010年度奖章获得者

发表于 2011-1-7 17:18 |显示全部楼层
此文章由 dalaohu 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 dalaohu 所有!转贴必须注明作者、出处和本声明,并保持内容完整
If your app pool/service recycled, your screwed

if it has to be a specific time, do a windows service to purge the cache.

If u using appfabric, there are other meches doing that.
头像被屏蔽

禁止发言

发表于 2011-1-8 20:54 |显示全部楼层
此文章由 澳贼 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 澳贼 所有!转贴必须注明作者、出处和本声明,并保持内容完整
“If your app pool/service recycled, your screwed” ?? 大师你给解释解释。为什么我会被暴力性爱??

原帖由 dalaohu 于 2011-1-7 17:18 发表
If your app pool/service recycled, your screwed

if it has to be a specific time, do a windows service to purge the cache.

If u using appfabric, there are other meches doing that.

评分

参与人数 1积分 +3 收起 理由
乱码 + 3 你太有才了

查看全部评分

签名被屏蔽
头像被屏蔽

禁止发言

发表于 2011-1-8 21:06 |显示全部楼层

this comment is interesting

此文章由 澳贼 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 澳贼 所有!转贴必须注明作者、出处和本声明,并保持内容完整
http://blogs.msdn.com/b/david.wa ... n-availability.aspx

David Wang 26 Jan 2006 9:24 PM #
Brian - Your intuition is on target; just missing some details. Let me explain...

Server applications, contrary to client applications, expect to run for a long period of time. Thus, a lot of server-side application employ caching to improve performance over time, at the expense of memory, for heavily used traffic patterns which may span across users.

For example, response to /default.aspx may be cached in memory such that after 1 user accesses it and pre-compile/caches it, the other 9 users immediately retrieves the URL without much processing. This is a huge performance win at the expense of spending memory to cache it.

In other words, the fact that after 10 users connect to an application, log off, and after half an hour the memory still remains used is insignificant. You have to accept that this may be the expected "working set" of your application.

What you should be concerned about is this -- suppose 10 users repeatedly log on/off and use the application over a period of time doing the same sort of thing and the memory used seems to increase without bound -- that is a sign of memory leak and must be addressed.

In other words, until you determine *through experimentation* the "working set" memory of that application, you cannot distinguish between "expected memory caching" (i.e. "working set") and "aggressive memory caching" (i.e. "memory leak"). And if you cannot distinguish between the two, arbitrary numbers like 160MB or invoking periodic recycling simply does not make sense.

It may be that for 10 users, your application's working set is 200MB after 1 hour and stays steady thereafter -- in which case you are prematurely worrying about nothing by looking at things in 30 minutes.

Sorry, there is no magic bullet nor calculation to automatically determine the proper metrics or need for recycling - it is all specific to the application and requires human experience to decide.
签名被屏蔽
头像被屏蔽

禁止发言

发表于 2011-1-11 21:16 |显示全部楼层

dalaohu

此文章由 澳贼 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 澳贼 所有!转贴必须注明作者、出处和本声明,并保持内容完整
dalaohu 能否回答问题???

发表于 2011-1-12 13:17 |显示全部楼层

你尽可以用别的手段

此文章由 混不到坑的萝卜 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 混不到坑的萝卜 所有!转贴必须注明作者、出处和本声明,并保持内容完整
比如说你的cached objects依赖于某个服务器上的文件。每次你有新数据的时候就把那个文件更新一下,那么你的cache也会更新。
参考:
http://www.dotnetfunda.com/artic ... ncy-in-aspnet-.aspx

用sliding 或者 absolute expiration对你来说不够用么?sliding的话会有dalaohu说的问题,absolute不会。

评分

参与人数 1积分 +2 收起 理由
澳贼 + 2 不好意思,就两分了。你也不在乎 ...

查看全部评分

Advertisement
Advertisement
头像被屏蔽

禁止发言

发表于 2011-1-12 13:48 |显示全部楼层
此文章由 澳贼 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 澳贼 所有!转贴必须注明作者、出处和本声明,并保持内容完整
问题是数据源是sql server,不依赖于某个服务器上的文件。

我上面的例子就是用absolute time

原帖由 混不到坑的萝卜 于 2011-1-12 13:17 发表
比如说你的cached objects依赖于某个服务器上的文件。每次你有新数据的时候就把那个文件更新一下,那么你的cache也会更新。
参考:
http://www.dotnetfunda.com/artic ... th-file-dependency- ...
签名被屏蔽

发表回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Advertisement
Advertisement
返回顶部