【发布时间】:2011-06-07 06:32:22
【问题描述】:
我能否在缓存中存储的对象上有效地同步锁定?
喜欢:
SyncLock System.Web.HttpContext.Current.Cache("Some Object")
'do some stuff that is threadsafe on this cached object'
End SyncLock
这会阻止另一个线程修改该缓存对象吗?
【问题讨论】:
我能否在缓存中存储的对象上有效地同步锁定?
喜欢:
SyncLock System.Web.HttpContext.Current.Cache("Some Object")
'do some stuff that is threadsafe on this cached object'
End SyncLock
这会阻止另一个线程修改该缓存对象吗?
【问题讨论】:
对于标准缓存,是的。但它不会阻止另一个线程替换缓存中的对象 - 您需要为此使用单独的同步对象。如果你碰巧使用了分布式缓存(例如 Velocity),那么它也不一定可靠。
【讨论】: