private void ResetEntity(CacheEntity cacheEntity) { GlobalCacheResult globalCacheResult = GlobalCache.Search(cacheEntity.ObjectId); if (_objList.ContainsKey(cacheEntity.Value)) { _objList.Remove(cacheEntity.Value); } cacheEntity.Value = globalCacheResult.Value; cacheEntity.Version = globalCacheResult.Version; _objList.Add(cacheEntity.Value, cacheEntity); }
private IList<object> GetObjectsFromGlobalCache(Type objType, QueryExpression expression, IList<Guid> ignoreIds) { List<object> result = new List<object>(); IEnumerable<GlobalCacheResult> globalCacheResults; foreach (CacheEntity cacheEntity in _deleteList) { ignoreIds.Add(cacheEntity.ObjectId); } globalCacheResults = GlobalCache.Search(objType, expression, _persistenceContext, ignoreIds); foreach (GlobalCacheResult globalCacheResult in globalCacheResults) { CacheEntity cacheEntity = new CacheEntity(); cacheEntity.ObjectId = globalCacheResult.ObjectId; cacheEntity.Value = globalCacheResult.Value; cacheEntity.Version = globalCacheResult.Version; cacheEntity.ForeignKeys = globalCacheResult.ForeignKeys; _objList.Add(cacheEntity.Value, cacheEntity); if (!_objTable.ContainsKey(objType)) { _objTable.Add(objType, new List<CacheEntity>()); } _objTable[objType].Add(cacheEntity); result.Add(cacheEntity.Value); } return result; }
private void RefreshCacheEntity(CacheEntity cacheEntity) { if (GlobalCache.GetObjectVersion(cacheEntity.ObjectId) > cacheEntity.Version) { GlobalCacheResult globalCacheResult = GlobalCache.Search(cacheEntity.ObjectId); cacheEntity.Value = globalCacheResult.Value; cacheEntity.Version = globalCacheResult.Version; cacheEntity.ForeignKeys = globalCacheResult.ForeignKeys; } }
public void Insert(object @object) { try { if (_objList.ContainsKey(@object)) { throw new Exception("The object exists"); } else { CacheEntity cacheEntity = new CacheEntity(); cacheEntity.ObjectId = Guid.NewGuid(); cacheEntity.Value = @object; cacheEntity.Version = DateTime.UtcNow.Ticks; _objList.Add(cacheEntity.Value, cacheEntity); if (!_objTable.ContainsKey(cacheEntity.Value.GetType())) { _objTable.Add(cacheEntity.Value.GetType(), new List<CacheEntity>()); } _objTable[cacheEntity.Value.GetType()].Add(cacheEntity); _insertList.Add(cacheEntity); } } catch (Exception ex) { RollBack(); throw ex; } }