【发布时间】:2012-10-24 09:01:19
【问题描述】:
MemoryCache 是一个线程安全的类,根据this 文章。但我不明白它在特定情况下会如何表现。例如我有代码:
static private MemoryCache _cache = MemoryCache.Default;
...
if (_cache.Contains("Test"))
{
return _cache.Get("Test") as string;
}
- 在我调用
Contains()之后元素的生存时间是否会过期,所以null值将被返回? - 在我调用
Contains()之后,另一个线程是否可以删除项目,所以null值将被返回?
【问题讨论】:
标签: c# caching concurrency thread-safety