缓存中对象的同步 [英] Synclock on an object in the Cache
本文介绍了缓存中对象的同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以有效地对缓存中存储的对象进行同步锁定吗?
Can I synclock effectively on an object stored in the cache?
赞:
SyncLock System.Web.HttpContext.Current.Cache("Some Object")
'do some stuff that is threadsafe on this cached object'
End SyncLock
这会阻止另一个线程修改该缓存的对象吗?
Will this stop another thread from modifying that cached object?
推荐答案
对于标准缓存,是的.但这不会阻止另一个线程替换缓存中的对象-为此,您需要使用单独的同步对象.而且,如果您碰巧正在使用分布式缓存(例如Velocity),那么它也不一定可靠.
For the standard cache, yes. But it won't stop another thread replacing the object in the cache - you'll need to use a separate sync object for that. And if you happen to be using a distributed cache (e.g. Velocity) then it's not necessarily reliable either.
这篇关于缓存中对象的同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文