MemoryCache是一个线程安全类,根据这的文章。但我不明白它在特定情况下会如何表现。例如,我有代码:
static private MemoryCache _cache = MemoryCache.Default;
...
if (_cache.Contains("Test"))
{
return _cache.Get("Test") as string;
}Contains()之后过期,从而返回null值?Contains()之后,另一个线程可以删除项以便返回null值吗?发布于 2012-10-24 09:05:30
是的,是的,这是常见的种族状况。如果简单地将代码编写为
var test = _cache.Get("Test");
if (test != null) {
return test as string;
}https://stackoverflow.com/questions/13045950
复制相似问题