public Dictionary <string, T> Get() { try { if (_useRedisCache == false || _dataCache == null) { return(new Dictionary <string, T>(_memoryCache)); } var data = _dataCache.HashGetAll(_dictionaryName, flags: CommandFlags.PreferSlave); if (data == null) { return(new Dictionary <string, T>()); } return(data.ToDictionary(k => (string)k.Name, v => _serializer.Deserialize <T>(v.Value))); } catch (Exception) { return(new Dictionary <string, T>()); } }
public T GetListItem <T>(string listName, int index) { try { var memList = GetMemory <List <T> >(listName); if (!_useDistributedCache) { if (memList.Count > index) { return(memList[index]); } return(default(T)); } var redisData = _rediscache.HashGet(listName, index, flags: CommandFlags.PreferSlave); if (!redisData.HasValue) { return(default(T)); } var redisItem = _serializer.Deserialize <T>(redisData); // Update the item in memory if (memList.Count > index) { memList[index] = redisItem; } return(redisItem); } catch (Exception) { return(default(T)); } }