/** <inheritDoc /> */ protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior) { if (_commandInfo.IsModification) { // Execute reader, then invalidate cached data. var dbReader = _command.ExecuteReader(behavior); InvalidateCache(); return(dbReader); } if (Transaction != null) { return(_command.ExecuteReader(behavior)); } var queryInfo = GetQueryInfo(); var strategy = _commandInfo.Policy.GetCachingMode(queryInfo); var cacheKey = _commandInfo.Cache.GetCacheKey(GetKey(), _commandInfo.AffectedEntitySets, strategy); object cachedRes; if (_commandInfo.Cache.GetItem(cacheKey, out cachedRes)) { return(((DataReaderResult)cachedRes).CreateReader()); } var reader = _command.ExecuteReader(behavior); if (reader.RecordsAffected > 0) { return(reader); // Queries that modify anything are never cached. } // Check if cacheable. if (!_commandInfo.Policy.CanBeCached(queryInfo)) { return(reader); } // Read into memory. var res = new DataReaderResult(reader); // Check if specific row count is cacheable. if (!_commandInfo.Policy.CanBeCached(queryInfo, res.RowCount)) { return(res.CreateReader()); } PutResultToCache(cacheKey, res, queryInfo); return(res.CreateReader()); }
/** <inheritDoc /> */ protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior) { if (_commandInfo.IsModification) { // Execute reader, then invalidate cached data. var dbReader = _command.ExecuteReader(behavior); InvalidateCache(); return dbReader; } if (Transaction != null) { return _command.ExecuteReader(behavior); } var queryInfo = GetQueryInfo(); var strategy = _commandInfo.Policy.GetCachingMode(queryInfo); var cacheKey = _commandInfo.Cache.GetCacheKey(GetKey(), _commandInfo.AffectedEntitySets, strategy); object cachedRes; if (_commandInfo.Cache.GetItem(cacheKey, out cachedRes)) return ((DataReaderResult) cachedRes).CreateReader(); var reader = _command.ExecuteReader(behavior); if (reader.RecordsAffected > 0) return reader; // Queries that modify anything are never cached. // Check if cacheable. if (!_commandInfo.Policy.CanBeCached(queryInfo)) return reader; // Read into memory. var res = new DataReaderResult(reader); // Check if specific row count is cacheable. if (!_commandInfo.Policy.CanBeCached(queryInfo, res.RowCount)) return res.CreateReader(); PutResultToCache(cacheKey, res, queryInfo); return res.CreateReader(); }