使用 ASP.NET 缓存实现视图计数
我需要在博客社区上实现每个帖子的浏览次数,所以我通过SO和Meta进行了研究,发现了很多相关的帖子,但对此没有明确的答案。
所以这里我打算使用asp.net缓存api以编程方式缓存一个List,并让缓存key为PostID。而我cahce是10分钟,所以10分钟内现有IP的访问都会被丢弃。而且,当缓存过期时,我计划使用 CacheItemRemovedCallback 处理程序来更新帖子视图计数的数据库。
该应用程序将在 Windows Azure 上运行,并使用多个 VM 来处理负载。所以想请教一下谁有这方面的经验,这个可行吗?缓存过期回调的可靠性如何?
谢谢。
I have the need to implement view count on a community of blogs for each post, so I researched through SO and Meta found many related posts, but there is no definite answer on this.
So here I plan to use asp.net cache api to programatically cache a List and let the cache key be the PostID. And I cahce it for 10 minutes, so within 10 minutes visits from an existing IP will be discarded. And, when the cache expires I plan to use the CacheItemRemovedCallback handler to update the database on the posts view counts.
This app will be run on Windows Azure with multiple VMs to handle load. So I'd like to ask who has experience on this, would this work and how reliable is the cache expiration callback?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:
抱歉,我错过了关于它在过程缓存中是常规的部分。我认为这是我见过的关于构建可扩展计数器的最好的文章(来自史蒂夫·马克思)
您的问题有一个相当简单的答案,基于 Azure 的缓存不支持回调。
它包含在缓存文档中,因为应用程序结构缓存的本地版本确实支持回调和其他几个功能。有关差异的完整列表,请参阅 MSDN 上的文章
EDIT:
Sorry, I'd missed the part about it being just regular in proc caching. I think this is the best article I've seen on building scalable counters (from Steve Marx)
There's a fairly simple answer to your question, callbacks are not support by Azure based caching.
It's included in the documentation for caching because the on premises version of app fabric caching does support callbacks and several other features. For a full list of the differences, there is an article on MSDN