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; }
internal MemCache(CacheCommon cacheCommon) : base(cacheCommon) { // config initialization is done by Init. Assembly asm = Assembly.Load("System.Runtime.Caching, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"); Type t = asm.GetType("System.Runtime.Caching.MemoryCache", true, false); _cacheInternal = HttpRuntime.CreateNonPublicInstance(t, new object[] {"asp_icache", null, true}) as MemoryCache; _cachePublic = HttpRuntime.CreateNonPublicInstance(t, new object[] {"asp_pcache", null, true}) as MemoryCache; }
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); }
internal CacheMultiple(CacheCommon cacheCommon, int numSingleCaches) : base(cacheCommon) { this._cacheIndexMask = numSingleCaches - 1; this._caches = new CacheSingle[numSingleCaches]; for (int i = 0; i < numSingleCaches; i++) { this._caches[i] = new CacheSingle(cacheCommon, this, i); } }
internal MemCache(CacheCommon cacheCommon) : base(cacheCommon) { // config initialization is done by Init. Assembly asm = Assembly.Load("System.Runtime.Caching, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"); Type t = asm.GetType("System.Runtime.Caching.MemoryCache", true, false); _cacheInternal = HttpRuntime.CreateNonPublicInstance(t, new object[] { "asp_icache", null, true }) as MemoryCache; _cachePublic = HttpRuntime.CreateNonPublicInstance(t, new object[] { "asp_pcache", null, true }) as MemoryCache; }
internal CacheSingle(CacheCommon cacheCommon, CacheMultiple cacheMultiple, int iSubCache) : base(cacheCommon) { this._cacheMultiple = cacheMultiple; this._iSubCache = iSubCache; this._entries = new Hashtable(CacheKeyComparer.GetInstance()); this._expires = new CacheExpires(this); this._usage = new CacheUsage(this); this._lock = new object(); this._insertBlock = new ManualResetEvent(true); }
protected CacheInternal(CacheCommon cacheCommon) { _cacheCommon = cacheCommon; }
// 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; }
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); } }
protected CacheInternal(CacheCommon cacheCommon) { this._cacheCommon = cacheCommon; }
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; // Each CacheSingle will have its own SRef reporting the size of the data it references. // Objects in this CacheSingle may have refs to the root Cache and therefore reference other instances of CacheSingle. // This leads to an unbalanced tree of SRefs and makes GC less efficient while calculating multiple SRefs on multiple cores. // Using DisposableGCHandleRef here prevents SRefs from calculating data that does not belong to other CacheSingle instances. _cachesRefs = new DisposableGCHandleRef<CacheSingle>[numSingleCaches]; for (int i = 0; i < numSingleCaches; i++) { _cachesRefs[i] = new DisposableGCHandleRef<CacheSingle>(new CacheSingle(cacheCommon, this, i)); } }
CacheMultiple _cacheMultiple; /* the CacheMultiple containing this cache */ /* * Constructs a new Cache. */ internal CacheSingle(CacheCommon cacheCommon, CacheMultiple cacheMultiple, int iSubCache) : base(cacheCommon) { _cacheMultiple = cacheMultiple; _iSubCache = iSubCache; _entries = new Hashtable(CacheKeyComparer.GetInstance()); _expires = new CacheExpires(this); _usage = new CacheUsage(this); _lock = new object(); _insertBlock = new ManualResetEvent(true); cacheCommon.AddSRefTarget(new { _entries, _expires, _usage }); }