/// <summary> /// Retrieve multiple query results from the cache. /// </summary> /// <param name="queryCache">The cache.</param> /// <param name="keys">The query keys.</param> /// <param name="queryParameters">The array of query parameters matching <paramref name="keys"/>.</param> /// <param name="returnTypes">The array of query result row types matching <paramref name="keys"/>.</param> /// <param name="spaces">The array of query spaces matching <paramref name="keys"/>.</param> /// <param name="session">The session for which the queries are executed.</param> /// <returns>The cached query results, matching each key of <paramref name="keys"/> respectively. For each /// missed key, it will contain a <see langword="null" />.</returns> public static IList[] GetMany( this IQueryCache queryCache, QueryKey[] keys, QueryParameters[] queryParameters, ICacheAssembler[][] returnTypes, ISet <string>[] spaces, ISessionImplementor session) { if (queryCache is IBatchableQueryCache batchableQueryCache) { return(batchableQueryCache.GetMany( keys, queryParameters, returnTypes, spaces, session)); } var results = new IList[keys.Length]; for (var i = 0; i < keys.Length; i++) { results[i] = queryCache.Get(keys[i], queryParameters[i], returnTypes[i], spaces[i], session); } return(results); }
/// <summary> /// Get query results from the cache. /// </summary> /// <param name="queryCache">The cache.</param> /// <param name="key">The query key.</param> /// <param name="queryParameters">The query parameters.</param> /// <param name="returnTypes">The query result row types.</param> /// <param name="spaces">The query spaces.</param> /// <param name="session">The session for which the query is executed.</param> /// <returns>The query results, if cached.</returns> public static IList Get( this IQueryCache queryCache, QueryKey key, QueryParameters queryParameters, ICacheAssembler[] returnTypes, ISet <string> spaces, ISessionImplementor session) { if (queryCache is IBatchableQueryCache batchableQueryCache) { return(batchableQueryCache.Get( key, queryParameters, returnTypes, spaces, session)); } if (!_hasWarnForObsoleteQueryCache) { _hasWarnForObsoleteQueryCache = true; Log.Warn("{0} is obsolete, it should implement {1}", queryCache, nameof(IBatchableQueryCache)); } var persistenceContext = session.PersistenceContext; var defaultReadOnlyOrig = persistenceContext.DefaultReadOnly; if (queryParameters.IsReadOnlyInitialized) { persistenceContext.DefaultReadOnly = queryParameters.ReadOnly; } else { queryParameters.ReadOnly = persistenceContext.DefaultReadOnly; } try { #pragma warning disable 618 return(queryCache.Get( #pragma warning restore 618 key, returnTypes, queryParameters.NaturalKeyLookup, spaces, session)); } finally { persistenceContext.DefaultReadOnly = defaultReadOnlyOrig; } }
public IList GetResultFromQueryCache(ISessionImplementor session, QueryParameters queryParameters, ISet<string> querySpaces, IQueryCache queryCache, QueryKey key) { if (!queryParameters.ForceCacheRefresh) { IList list = queryCache.Get(key, new ICacheAssembler[] {this}, queryParameters.NaturalKeyLookup, querySpaces, session); //we had to wrap the query results in another list in order to save all //the queries in the same bucket, now we need to do it the other way around. if (list != null) { list = (IList) list[0]; } return list; } return null; }
public IList GetResultFromQueryCache(ISessionImplementor session, QueryParameters queryParameters, ISet <string> querySpaces, IQueryCache queryCache, QueryKey key) { if (!queryParameters.ForceCacheRefresh) { IList list = queryCache.Get(key, new ICacheAssembler[] { this }, queryParameters.NaturalKeyLookup, querySpaces, session); //we had to wrap the query results in another list in order to save all //the queries in the same bucket, now we need to do it the other way around. if (list != null) { list = (IList)list[0]; } return(list); } return(null); }
public virtual DataSet GetDataSet(string sql, IDbDataParameter[] paramters = null) { QueryKey key = new QueryKey(sql, new QueryParameters(paramters)); DataSet result = (DataSet)cache.Get(key); if (result != null) { return(result); } IDbDataAdapter adapter = CreateAdapter(); DataSet ds = GetDataSet(adapter, sql, paramters); cache.Put(key, ds, DateTime.Now.AddMinutes(1).Ticks); return(ds); }
private IList GetResultFromQueryCache(ISessionImplementor session, QueryParameters queryParameters, ISet<string> querySpaces, IType[] resultTypes, IQueryCache queryCache, QueryKey key) { IList result = null; if ((!queryParameters.ForceCacheRefresh) && (session.CacheMode & CacheMode.Get) == CacheMode.Get) { result = queryCache.Get(key, resultTypes, queryParameters.NaturalKeyLookup, querySpaces, session); if (factory.Statistics.IsStatisticsEnabled) { if (result == null) { factory.StatisticsImplementor.QueryCacheMiss(QueryIdentifier, queryCache.RegionName); } else { factory.StatisticsImplementor.QueryCacheHit(QueryIdentifier, queryCache.RegionName); } } } return result; }
private IList GetResultFromQueryCache(ISessionImplementor session, QueryParameters queryParameters, ISet<string> querySpaces, IType[] resultTypes, IQueryCache queryCache, QueryKey key) { IList result = null; if ((!queryParameters.ForceCacheRefresh) && (session.CacheMode & CacheMode.Get) == CacheMode.Get) { IPersistenceContext persistenceContext = session.PersistenceContext; bool defaultReadOnlyOrig = persistenceContext.DefaultReadOnly; if (queryParameters.IsReadOnlyInitialized) persistenceContext.DefaultReadOnly = queryParameters.ReadOnly; else queryParameters.ReadOnly = persistenceContext.DefaultReadOnly; try { result = queryCache.Get(key, resultTypes, queryParameters.NaturalKeyLookup, querySpaces, session); if (_factory.Statistics.IsStatisticsEnabled) { if (result == null) { _factory.StatisticsImplementor.QueryCacheMiss(QueryIdentifier, queryCache.RegionName); } else { _factory.StatisticsImplementor.QueryCacheHit(QueryIdentifier, queryCache.RegionName); } } } finally { persistenceContext.DefaultReadOnly = defaultReadOnlyOrig; } } return result; }
private static IList GetResultFromQueryCache(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes, IQueryCache queryCache, QueryKey key) { if (!queryParameters.ForceCacheRefresh) { return queryCache.Get(key, resultTypes, querySpaces, session); } return null; }