internal static CacheInternal Create()
 {
     CacheInternal internal2;
     CacheCommon cacheCommon = new CacheCommon();
     int numSingleCaches = 0;
     uint numProcessCPUs = (uint) SystemInfo.GetNumProcessCPUs();
     numSingleCaches = 1;
     numProcessCPUs--;
     while (numProcessCPUs > 0)
     {
         numSingleCaches = numSingleCaches << 1;
         numProcessCPUs = numProcessCPUs >> 1;
     }
     if (numSingleCaches == 1)
     {
         internal2 = new CacheSingle(cacheCommon, null, 0);
     }
     else
     {
         internal2 = new CacheMultiple(cacheCommon, numSingleCaches);
     }
     cacheCommon.SetCacheInternal(internal2);
     cacheCommon.ResetFromConfigSettings();
     return internal2;
 }
Beispiel #2
0
        internal static CacheInternal Create()
        {
            CacheInternal internal2;
            CacheCommon   cacheCommon     = new CacheCommon();
            int           numSingleCaches = 0;
            uint          numProcessCPUs  = (uint)SystemInfo.GetNumProcessCPUs();

            numSingleCaches = 1;
            numProcessCPUs--;
            while (numProcessCPUs > 0)
            {
                numSingleCaches = numSingleCaches << 1;
                numProcessCPUs  = numProcessCPUs >> 1;
            }
            if (numSingleCaches == 1)
            {
                internal2 = new CacheSingle(cacheCommon, null, 0);
            }
            else
            {
                internal2 = new CacheMultiple(cacheCommon, numSingleCaches);
            }
            cacheCommon.SetCacheInternal(internal2);
            cacheCommon.ResetFromConfigSettings();
            return(internal2);
        }
Beispiel #3
0
        // common implementation
        static internal CacheInternal Create() {
            CacheCommon cacheCommon = new CacheCommon();
            CacheInternal cacheInternal;
#if USE_MEMORY_CACHE
            if (UseMemoryCache) {
                cacheInternal = new MemCache(cacheCommon);
                cacheCommon.AddSRefTarget(cacheInternal);
            }
            else {
#endif
                int numSubCaches = 0;
                uint numCPUs = (uint) SystemInfo.GetNumProcessCPUs();
                // the number of subcaches is the minimal power of 2 greater
                // than or equal to the number of cpus
                numSubCaches = 1;
                numCPUs -= 1;
                while (numCPUs > 0) {
                    numSubCaches <<= 1;
                    numCPUs >>= 1;
                }
                if (numSubCaches == 1) {
                    cacheInternal = new CacheSingle(cacheCommon, null, 0);
                }
                else {
                    cacheInternal = new CacheMultiple(cacheCommon, numSubCaches);
                }
#if USE_MEMORY_CACHE
            }
#endif
            cacheCommon.SetCacheInternal(cacheInternal);
            cacheCommon.ResetFromConfigSettings();

            return cacheInternal;
        }
Beispiel #4
0
 internal CacheMultiple(CacheCommon cacheCommon, int numSingleCaches) : base(cacheCommon) {
     Debug.Assert(numSingleCaches > 1, "numSingleCaches is not greater than 1");
     Debug.Assert((numSingleCaches & (numSingleCaches - 1)) == 0, "numSingleCaches is not a power of 2");
     _cacheIndexMask = numSingleCaches - 1;
     _caches = new CacheSingle[numSingleCaches];
     for (int i = 0; i < numSingleCaches; i++) {
         _caches[i] = new CacheSingle(cacheCommon, this, i);
     }
 }
        internal int FlushExpiredItems(DateTime utcNow, bool useInsertBlock)
        {
            ExpiresEntry[]  entryArray;
            int             index;
            CacheEntry      entry;
            ExpiresEntryRef ref3;
            ExpiresEntryRef ref4;

            if ((this._cEntriesInUse == 0) || (this.GetExpiresCount(utcNow) == 0))
            {
                return(0);
            }
            ExpiresEntryRef iNVALID = ExpiresEntryRef.INVALID;
            int             num2    = 0;

            try
            {
                if (useInsertBlock)
                {
                    this._cacheExpires.CacheSingle.BlockInsertIfNeeded();
                }
                lock (this)
                {
                    if ((this._cEntriesInUse == 0) || (this.GetExpiresCount(utcNow) == 0))
                    {
                        return(0);
                    }
                    this.ResetCounts(utcNow);
                    int num3 = this._cPagesInUse;
                    for (int i = 0; i < this._pages.Length; i++)
                    {
                        entryArray = this._pages[i]._entries;
                        if (entryArray != null)
                        {
                            int num5 = 0x7f - entryArray[0]._cFree;
                            for (int j = 1; j < entryArray.Length; j++)
                            {
                                entry = entryArray[j]._cacheEntry;
                                if (entry != null)
                                {
                                    if (entryArray[j]._utcExpires > utcNow)
                                    {
                                        this.AddCount(entryArray[j]._utcExpires);
                                    }
                                    else
                                    {
                                        entry.ExpiresBucket   = 0xff;
                                        entry.ExpiresEntryRef = ExpiresEntryRef.INVALID;
                                        entryArray[j]._cFree  = 1;
                                        entryArray[j]._next   = iNVALID;
                                        iNVALID = new ExpiresEntryRef(i, j);
                                        num2++;
                                        this._cEntriesInFlush++;
                                    }
                                    num5--;
                                    if (num5 == 0)
                                    {
                                        break;
                                    }
                                }
                            }
                            num3--;
                            if (num3 == 0)
                            {
                                break;
                            }
                        }
                    }
                    if (num2 == 0)
                    {
                        return(0);
                    }
                    this._blockReduce = true;
                }
            }
            finally
            {
                if (useInsertBlock)
                {
                    this._cacheExpires.CacheSingle.UnblockInsert();
                }
            }
            CacheSingle cacheSingle = this._cacheExpires.CacheSingle;

            for (ref3 = iNVALID; !ref3.IsInvalid; ref3 = ref4)
            {
                entryArray = this._pages[ref3.PageIndex]._entries;
                index      = ref3.Index;
                ref4       = entryArray[index]._next;
                entry      = entryArray[index]._cacheEntry;
                entryArray[index]._cacheEntry = null;
                cacheSingle.Remove(entry, CacheItemRemovedReason.Expired);
            }
            try
            {
                if (useInsertBlock)
                {
                    this._cacheExpires.CacheSingle.BlockInsertIfNeeded();
                }
                lock (this)
                {
                    for (ref3 = iNVALID; !ref3.IsInvalid; ref3 = ref4)
                    {
                        entryArray = this._pages[ref3.PageIndex]._entries;
                        index      = ref3.Index;
                        ref4       = entryArray[index]._next;
                        this._cEntriesInFlush--;
                        this.AddExpiresEntryToFreeList(ref3);
                    }
                    this._blockReduce = false;
                    this.Reduce();
                }
            }
            finally
            {
                if (useInsertBlock)
                {
                    this._cacheExpires.CacheSingle.UnblockInsert();
                }
            }
            return(num2);
        }
Beispiel #6
0
        internal int FlushUnderUsedItems(int maxFlush, bool force, ref int publicEntriesFlushed, ref int ocEntriesFlushed)
        {
            UsageEntry[]  entryArray;
            int           num;
            CacheEntry    entry;
            UsageEntryRef ref6;
            UsageEntryRef ref7;

            if (this._cEntriesInUse == 0)
            {
                return(0);
            }
            UsageEntryRef iNVALID = UsageEntryRef.INVALID;
            int           num2    = 0;

            try
            {
                this._cacheUsage.CacheSingle.BlockInsertIfNeeded();
                lock (this)
                {
                    UsageEntryRef ref4;
                    if (this._cEntriesInUse == 0)
                    {
                        return(0);
                    }
                    DateTime utcNow = DateTime.UtcNow;
                    for (UsageEntryRef ref3 = this._lastRefTail; (this._cEntriesInFlush < maxFlush) && !ref3.IsInvalid; ref3 = ref4)
                    {
                        for (ref4 = this._pages[ref3.PageIndex]._entries[ref3.Ref2Index]._ref2._prev; ref4.IsRef1; ref4 = this._pages[ref4.PageIndex]._entries[ref4.Ref1Index]._ref1._prev)
                        {
                        }
                        entryArray = this._pages[ref3.PageIndex]._entries;
                        num        = ref3.Ref2Index;
                        if (!force)
                        {
                            DateTime time = entryArray[num]._utcDate;
                            if (((utcNow - time) <= CacheUsage.NEWADD_INTERVAL) && (utcNow >= time))
                            {
                                continue;
                            }
                        }
                        UsageEntryRef entryRef = new UsageEntryRef(ref3.PageIndex, ref3.Ref2Index);
                        entry = entryArray[num]._cacheEntry;
                        entry.UsageEntryRef = UsageEntryRef.INVALID;
                        if (entry.IsPublic)
                        {
                            publicEntriesFlushed++;
                        }
                        else if (entry.IsOutputCache)
                        {
                            ocEntriesFlushed++;
                        }
                        this.RemoveEntryFromLastRefList(entryRef);
                        entryArray[num]._ref1._next = iNVALID;
                        iNVALID = entryRef;
                        num2++;
                        this._cEntriesInFlush++;
                    }
                    if (num2 == 0)
                    {
                        return(0);
                    }
                    this._blockReduce = true;
                }
            }
            finally
            {
                this._cacheUsage.CacheSingle.UnblockInsert();
            }
            CacheSingle cacheSingle = this._cacheUsage.CacheSingle;

            for (ref6 = iNVALID; !ref6.IsInvalid; ref6 = ref7)
            {
                entryArray = this._pages[ref6.PageIndex]._entries;
                num        = ref6.Ref1Index;
                ref7       = entryArray[num]._ref1._next;
                entry      = entryArray[num]._cacheEntry;
                entryArray[num]._cacheEntry = null;
                cacheSingle.Remove(entry, CacheItemRemovedReason.Underused);
            }
            try
            {
                this._cacheUsage.CacheSingle.BlockInsertIfNeeded();
                lock (this)
                {
                    for (ref6 = iNVALID; !ref6.IsInvalid; ref6 = ref7)
                    {
                        entryArray = this._pages[ref6.PageIndex]._entries;
                        num        = ref6.Ref1Index;
                        ref7       = entryArray[num]._ref1._next;
                        this._cEntriesInFlush--;
                        this.AddUsageEntryToFreeList(ref6);
                    }
                    this._blockReduce = false;
                    this.Reduce();
                }
            }
            finally
            {
                this._cacheUsage.CacheSingle.UnblockInsert();
            }
            return(num2);
        }