AppFabric 超时通知
我已在 AppFabric 上启用通知,并且在添加期间指定的超时后从缓存中删除项目时,我尝试收到通知。 例如:
TimeSpan timeout = new TimeSpan(0,0,10);
m_cache.Add(OrderId.Text, order, timeout);
m_cache.AddItemLevelCallback(OrderId.Text,DataCacheOperations.RemoveItem,myCacheLvlDelegate);
我在“myCacheLvlDelegate”方法中放置了一个断点,但即使在 10 秒超时(测试)之后也永远不会到达该断点。 出于测试目的,我在之后显式调用
m_cache.Remove(OrderId.Text);
,然后调用了委托!
因此,仅当我显式调用删除函数时才会调用委托方法,但如果超时到期则不会调用委托方法...
您是否有一种解决方案可以在超时后获取通知(在添加期间指定的通知)?
我需要它,因为我想在超时后调用 Web 服务来刷新数据并再次缓存结果。
谢谢你,
法布里斯
I have enabled notification on AppFabric and I'm trying to get notified when an item is removed from the cache after the timeout specified during the Add.
Ex :
TimeSpan timeout = new TimeSpan(0,0,10);
m_cache.Add(OrderId.Text, order, timeout);
m_cache.AddItemLevelCallback(OrderId.Text,DataCacheOperations.RemoveItem,myCacheLvlDelegate);
I put a breakpoint in the "myCacheLvlDelegate" method but it is never reached even after the 10s timeout (test).
For test purpose, I have called explicitly
m_cache.Remove(OrderId.Text);
after and then the delegate was called !
So the delegate method is only called if I explicitly call the Remove function but not if the timeout expire...
Do you have a solution to get notify after the timeout (the one specified during the add) ?
I need it because I would like to call a webservice after the timeout to refresh data and cache the result again.
Thank you,
Fabrice
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您真正需要的是在特定时间间隔提醒您刷新 Appfabric 缓存项。
您可以尝试将 AppFabric 缓存与 Microsoft Enterprise Library 中的 Caching 块结合使用。缓存块使您能够在项目即将过期时收到通知。但这会创建两个缓存。
将对象标识符存储在应用程序块提供的缓存中,并具有必要的超时间隔,而您可以将实际数据“放入”AppFabric 缓存中,而无需超时间隔。使用“放置”而不是“添加”以确保替换对象(如果存在),否则创建它。
What you really need is to be reminded at specific intervals to refresh the Appfabric cache items.
You could try using the AppFabric cache in conjunction with the Caching block from the Microsoft Enterprise Library. The caching block provides you with the ability to be notified when the item is about to expire. This though will create two caches.
Store an object identifier in the cache provided by the application block with the necessary timeout interval, while you can "Put" the actual data in the AppFabric cache without a timeout interval. Use the "Put" instead of the "Add" to ensure that you replace the object if it exists else create it.
我不认为你能够做到这一点,因为我不认为回调机制是为这种事情设计的。我可以看到您想要实现的目标,也可以看到您是如何得出这个问题的,但我认为只要您的客户端在您接触缓存的任何地方都使用缓存旁路模式,您就会得到影响。
为了进行审查,缓存旁模式为:
例如
这样,缓存的订单永远不会超过十秒,因为如果超时超出缓存,下一个调用者将从缓存中获取空结果,并再次调用Web服务从Web服务获取订单。您将获得相同的效果,但由于缓存将按需填充,您应该会看到对服务器的影响较小,因为它不会每十秒旋转一次 Web 服务请求。
I don't think you'll be able to do this, as I don't think this sort of thing is what the callback mechanism was designed for. I can see what you're trying to achieve, and I can see how you've arrived at this question, but I think as long as your client uses the cache-aside pattern everywhere you're touching the cache you'll get the effect.
For review, the cache-aside pattern is:
e.g.
In this way, the cached order will never be more than ten seconds old, because if it times out of the cache, the next caller will get a null result from the cache and call the web service again to get the order from the web service. You'll get the same effect, but as the cache will be filled on demand you should see a lower impact on your server as it won't be spinning up a web service request every ten seconds.
我现在不知道这个问题是否具有深刻的意义,但是如果 appfabric 中的某个项目过期,则在过期后将检索通知。即使是item级别的回调或者cache级别的回调。
我的代码是
插入方法是
并且它适当地发出所有操作的通知。过期通知仅在该项目从内存中被逐出后才会发出,而不是在 TTL(生存时间)结束时发出。我已经从微软确认了这一点。您应该稍等一下才能收到通知。
I don't now if the question is of deep meaning, but if an item expires in appfabric, the notification will be retrieved after it is expired. Even if it is item level callback or cache level call back.
My code is
And insert method is
And it is duely giving the notifications for all operations. The notification for expiration will come only after the item is evicted from memory not when the TTL (time to live) is over. I have confirmed this from Microsoft. you should wait a bit to get notifications.