/// <summary>Gets a cached plan for the given statement, if available.</summary> /// <remarks> /// If a plan is found, it is referenced for the LRU, and disowned by the cache. /// The client must call Release to return the plan to the cache. /// If no plan is found, null is returned and the cache is unaffected. /// </remarks> public ServerPlan Get(ServerProcess process, string statement, int contextHashCode) { ServerPlan plan = null; CachedPlanHeader header = GetPlanHeader(process, statement, contextHashCode); CachedPlans bumped = null; lock (this) { if (_plans != null) { CachedPlans plans; if (_plans.TryGetValue(header, out plans)) { for (int planIndex = plans.Count - 1; planIndex >= 0; planIndex--) { plan = plans[planIndex]; plans.RemoveAt(planIndex); if (process.Catalog.PlanCacheTimeStamp > plan.PlanCacheTimeStamp) { DisposeCachedPlan(process, plan); plan = null; } else { bumped = _plans.Reference(header, plans); break; } } } } } if (bumped != null) { DisposeCachedPlans(process, bumped); } if (plan != null) { plan.BindToProcess(process); } return(plan); }
public Schema.CatalogObjectHeaders Resolve(string name) { lock (this) { if (_cache != null) { Schema.CatalogObjectHeaders headers; if (_cache.TryGetValue(name, out headers)) { _cache.Reference(name, headers); } return(headers); } } return(null); }