How can I lock by cache key?
问题 I am trying to implement a generic thread-safe Cache method, and I wonder how I should implement the lock in it. It should look something like this: //private static readonly lockObject = new Object(); public T GetCache<T>(string key, Func<T> valueFactory...) { // try to pull from cache here lock (lockObject) // I don't want to use static object lock here because then every time a lock is performed, all cached objects in my site have to wait, regarding of the cache key. { // cache was empty