// 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; }
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(this); }