Implementing view count using ASP.NET cache
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.
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
精彩评论