public void SetVersionItems <T>(string key, CacheVersion <T> cacheVersion) where T : class { using (_rwLock.GetWriteLock()) { _cache.Set <CacheVersion <T> >(key, cacheVersion); } }
public CacheManager <T> SetVersionItems(string key, CacheVersion <T> cacheVersion) { if (!_cacheEnabled) { return(this); } var realkey = GetRealKey(key); realkey = "ls;" + realkey; _cache.SetVersionItems <T>(realkey, cacheVersion); return(this); }
public List <T> GetVersionItems(string key, Func <List <T> > acquirer) { if (!_cacheEnabled) { return(acquirer()); } var realkey = GetRealKey(key); realkey = "ls;" + realkey; int version = _cache.GetTObject <int>(_cacheVersion); var result = _cache.GetVersionItems <T>(realkey); bool updateCache; if (result != null) { if (result.Version == version) { return(Clone(result.Items)); } else { updateCache = true; } } else { updateCache = true; } if (updateCache) { var items = acquirer(); if (items == null) { return(items); } var cacheVersion = new CacheVersion <T>() { Version = version, Items = items }; SetVersionItems(key, cacheVersion); return(Clone(items)); } return(null); }