I have a class like this:
public static class CacheManager { static object lockObject = new object(); static MemcachedClient CacheObject { get { if (!MemcachedClient.Exists(Settings.Default .CacheInstanceName)) { MemcachedClient.Setup(Settings.Default .CacheInstanceName, new string[] {Settings.Default .CacheHostAddress}); }
it is used in repository classes:
public class NewsRepository : BaseRepository, IRepository { public List<News> FindAll() { return CacheManager.Get<News>(key, () => clientEntities.News.OrderByDescending(n => n.DateCreated).Select(n => n.NewsId).ToList(), (id) => clientEntities.News.Single(n => n.NewsId == id)); } } public class PagesRepository : BaseRepository { public List<Page> FindAll() { return CacheManager.Get<Page>(key, () => clientEntities.Pages.OrderBy(p => p.PageId).Select(p => p.PageId).ToList(), (id) => clientEntities.Pages.Single(p => p.PageId == id)); } }
my question is: for example, NewsRepository did not find the news in the cache and got a lock and started loading data, but at that moment PagesRepository did not find the pages in the cache. will the PagesRepository CacheManager lock NewsRepository or (it seems to me) the NewsRepository CacheManager is another static class and its internal locks do not affect the PagesRepository CacheManager?
source share