caching

How can I lock by cache key?

為{幸葍}努か 提交于 2020-11-26 11:07:27
问题 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

How can I lock by cache key?

☆樱花仙子☆ 提交于 2020-11-26 11:04:06
问题 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

How can I lock by cache key?

随声附和 提交于 2020-11-26 10:58:13
问题 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