/// <summary> /// Gets an entitycommanddefinition from cache if a match is found for the given cache key. /// </summary> /// <param name="entityCommandDefinition">out param. returns the entitycommanddefinition for a given cache key</param> /// <returns>true if a match is found in cache, false otherwise</returns> private bool TryGetEntityCommandDefinitionFromQueryCache(out EntityCommandDefinition entityCommandDefinition) { Debug.Assert(null != _connection, "Connection must not be null at this point"); entityCommandDefinition = null; // // if EnableQueryCaching is false, then just return to force the CommandDefinition to be created // if (!this._enableQueryPlanCaching || string.IsNullOrEmpty(this._esqlCommandText)) { return(false); } // // Create cache key // EntityClientCacheKey queryCacheKey = new EntityClientCacheKey(this); // // Try cache lookup // QueryCacheManager queryCacheManager = _connection.GetMetadataWorkspace().GetQueryCacheManager(); Debug.Assert(null != queryCacheManager, "QuerycacheManager instance cannot be null"); if (!queryCacheManager.TryCacheLookup(queryCacheKey, out entityCommandDefinition)) { // // if not, construct the command definition using no special options; // entityCommandDefinition = CreateCommandDefinition(); // // add to the cache // QueryCacheEntry outQueryCacheEntry = null; if (queryCacheManager.TryLookupAndAdd(new QueryCacheEntry(queryCacheKey, entityCommandDefinition), out outQueryCacheEntry)) { entityCommandDefinition = (EntityCommandDefinition)outQueryCacheEntry.GetTarget(); } } Debug.Assert(null != entityCommandDefinition, "out entityCommandDefinition must not be null"); return(true); }
private bool TryGetEntityCommandDefinitionFromQueryCache( out EntityCommandDefinition entityCommandDefinition) { entityCommandDefinition = (EntityCommandDefinition)null; if (!this._enableQueryPlanCaching || string.IsNullOrEmpty(this._esqlCommandText)) { return(false); } EntityClientCacheKey key = new EntityClientCacheKey(this); QueryCacheManager queryCacheManager = this._connection.GetMetadataWorkspace().GetQueryCacheManager(); if (!queryCacheManager.TryCacheLookup <EntityClientCacheKey, EntityCommandDefinition>(key, out entityCommandDefinition)) { entityCommandDefinition = this.CreateCommandDefinition(); QueryCacheEntry outQueryCacheEntry = (QueryCacheEntry)null; if (queryCacheManager.TryLookupAndAdd(new QueryCacheEntry((QueryCacheKey)key, (object)entityCommandDefinition), out outQueryCacheEntry)) { entityCommandDefinition = (EntityCommandDefinition)outQueryCacheEntry.GetTarget(); } } return(true); }