public void Add(string name, Schema.CatalogObjectHeaders headers)
 {
     lock (this)
     {
         if (_cache != null)
         {
             _cache.Reference(name, headers);
         }
     }
 }
Esempio n. 2
0
        public void Run()
        {
            Random LRandom = new Random();

            for (int j = 0; j < FIterations; j++)
            {
                int LEntry;
                for (int i = 0; i < FAccessCount; i++)
                {
                    LEntry = LRandom.Next(1, FSeed);
                    switch (LRandom.Next(1, 10))
                    {
                    case 1:
                    case 2:
                    case 3:
                        FFixedSizeCache.Add(FixedSizeCacheTest.GetKey(LEntry), FixedSizeCacheTest.GetValue(LEntry));
                        break;

                    case 4:
                    case 5:
                    case 6:
                        FFixedSizeCache[FixedSizeCacheTest.GetKey(LEntry)] = FixedSizeCacheTest.GetValue(LRandom.Next(1, FSeed));
                        break;

                    case 8:
                        FFixedSizeCache.Reference(FixedSizeCacheTest.GetKey(LEntry), FixedSizeCacheTest.GetValue(LEntry));
                        break;

                    default:
                        FFixedSizeCache.Remove(FixedSizeCacheTest.GetKey(LEntry));
                        break;
                    }
                }
            }
        }
Esempio n. 3
0
        /// <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);
        }
Esempio n. 4
0
        public void Reference()
        {
            string LReference = null;
            int    LCacheSize = 2;

            FTestCache = new FixedSizeCache <string, string>(LCacheSize);
            for (int i = 1; i <= FTestCache.Size; i++)
            {
                LReference = FTestCache.Reference(GetKey(i), GetValue(i));
                Assert.AreEqual(i, FTestCache.Count);
                Assert.True(FTestCache.ContainsKey(GetKey(i)));
                Assert.AreEqual(FTestCache[GetKey(i)], GetValue(i));
                Assert.IsNull(LReference);
            }
            Assert.AreEqual(LCacheSize, FTestCache.Count);

            LReference = FTestCache.Reference(GetKey(1), GetValue(1));

            Assert.IsNull(LReference);

            LReference = null;
            LCacheSize = 5;
            FTestCache = new FixedSizeCache <string, string>(LCacheSize);
            for (int i = 1; i <= FTestCache.Size; i++)
            {
                LReference = FTestCache.Reference(GetKey(i), GetValue(i));
                Assert.AreEqual(i, FTestCache.Count);
                Assert.True(FTestCache.ContainsKey(GetKey(i)));
                Assert.AreEqual(FTestCache[GetKey(i)], GetValue(i));
                Assert.IsNull(LReference);
            }
            Assert.AreEqual(LCacheSize, FTestCache.Count);

            LReference = FTestCache.Reference(GetKey(FTestCache.Size + 1), GetValue(FTestCache.Size + 1));
            Assert.AreEqual(LCacheSize, FTestCache.Count);
            Assert.IsNotNull(LReference);
            Assert.True(ValidateList());
        }
Esempio n. 5
0
        public void InternalReference()
        {
            try
            {
                ReflectionPermission LReflectionPermission = new ReflectionPermission(ReflectionPermissionFlag.RestrictedMemberAccess | ReflectionPermissionFlag.AllFlags);
                LReflectionPermission.Assert();

                // Entries don't get promoted until Correlated Period is exceeded and when they do they are promoted to Head
                FTestCache = new FixedSizeCache <string, string>(25);
                while (TestEntry < FTestCache.Size)
                {
                    IncrementTestEntry();
                }
                FixedSizeCache <string, string> .Entry LEntry = GetPrior(GetHead());
                Assert.AreNotEqual(GetHead(), LEntry);
                int LLocation = GetLocation(LEntry);
                for (int i = (FTestCache.Size - GetLastAccess(LEntry)); i < FixedSizeCache <string, string> .DefaultCorrelatedReferencePeriod; i++)
                {
                    FTestCache.Reference(LEntry.Key, LEntry.Value);
                    Assert.AreEqual(LLocation, GetLocation(LEntry));
                }

                FTestCache.Reference(LEntry.Key, LEntry.Value);
                Assert.AreNotEqual(LLocation, GetLocation(LEntry));
                Assert.AreEqual(GetHead(), LEntry);
                Assert.True(ValidateList());

                // Entries PreCutoff get demoted to not PreCutoff
                TestSetUp();
                FTestCache = new FixedSizeCache <string, string>(25);
                while (TestEntry < FTestCache.Size)
                {
                    IncrementTestEntry();
                    Assert.True(ValidateCutoff());
                }

                LEntry = GetHead();
                FixedSizeCache <string, string> .Entry LReferenced;
                FixedSizeCache <string, string> .Entry LTail;

                Assert.True(GetPreCutoff(LEntry));
                int LPreCutoffCount = PreCutoffCount();
                int LMoveCount      = 0;
                while (LMoveCount < LPreCutoffCount)
                {
                    LTail = GetTail();
                    if (LEntry == LTail)
                    {
                        LReferenced = LTail.GetType().GetField(CNextName, CFieldFlags).GetValue(LTail) as FixedSizeCache <string, string> .Entry;
                    }
                    else
                    {
                        LReferenced = LTail;
                    }
                    Assert.True(ValidateCutoff());
                    Assert.False(GetPreCutoff(LReferenced));
                    FTestCache.Reference(LReferenced.Key, LReferenced.Value);
                    if (GetPreCutoff(LReferenced))
                    {
                        LMoveCount++;
                    }
                }
                Assert.False(GetPreCutoff(LEntry));
                Assert.True(ValidateList());
            }
            finally
            {
                CodeAccessPermission.RevertAssert();
            }
        }
Esempio n. 6
0
 private void ReferenceName(string name)
 {
     Remove(_cache.Reference(name, null));
 }