示例#1
0
        public virtual long RamBytesUsed()
        {
            // LUCENENET specific - moved Reflection calls outside of the lock (similar to CachingWrapperFilter) to improve performance.

            // Sync only to pull the current set of values:
            IList <CachedOrds> cachedOrdsList;

            UninterruptableMonitor.Enter(syncLock);
            try
            {
                cachedOrdsList = new List <CachedOrds>();
#if FEATURE_CONDITIONALWEAKTABLE_ENUMERATOR
                foreach (var pair in ordsCache)
                {
                    cachedOrdsList.Add(pair.Value);
                }
#else
                // LUCENENET specific - since .NET Standard 2.0 and .NET Framework don't have a CondtionalWeakTable enumerator,
                // we use a weak event to retrieve the CachedOrds instances. We look each of these up here to avoid the need
                // to attach events to the CachedOrds instances themselves (thus using the existing IndexReader.Dispose()
                // method to detach the events rather than using a finalizer in CachedOrds to ensure they are cleaned up).
                var e = new Events.GetCacheKeysEventArgs();
                eventAggregator.GetEvent <Events.GetCacheKeysEvent>().Publish(e);
                foreach (var key in e.CacheKeys)
                {
                    if (ordsCache.TryGetValue(key, out CachedOrds value))
                    {
                        cachedOrdsList.Add(value);
                    }
                }
#endif
            }
            finally
            {
                UninterruptableMonitor.Exit(syncLock);
            }

            long total = 0;
            foreach (CachedOrds ord in cachedOrdsList)
            {
                total += ord.RamBytesUsed();
            }

            return(total);
        }
示例#2
0
        /// <summary>
        /// Returns total byte size used by cached filters. </summary>
        public virtual long GetSizeInBytes()
        {
            // Sync only to pull the current set of values:
            IList <DocIdSet> docIdSets;

            UninterruptableMonitor.Enter(cache);
            try
            {
                docIdSets = new JCG.List <DocIdSet>();
#if FEATURE_CONDITIONALWEAKTABLE_ENUMERATOR
                foreach (var pair in cache)
                {
                    docIdSets.Add(pair.Value);
                }
#else
                // LUCENENET specific - since .NET Standard 2.0 and .NET Framework don't have a CondtionalWeakTable enumerator,
                // we use a weak event to retrieve the DocIdSet instances. We look each of these up here to avoid the need
                // to attach events to the DocIdSet instances themselves (thus using the existing IndexReader.Dispose()
                // method to detach the events rather than using a finalizer in DocIdSet to ensure they are cleaned up).
                var e = new Events.GetCacheKeysEventArgs();
                eventAggregator.GetEvent <Events.GetCacheKeysEvent>().Publish(e);
                foreach (var key in e.CacheKeys)
                {
                    if (cache.TryGetValue(key, out DocIdSet value))
                    {
                        docIdSets.Add(value);
                    }
                }
#endif
            }
            finally
            {
                UninterruptableMonitor.Exit(cache);
            }

            long total = 0;
            foreach (DocIdSet dis in docIdSets)
            {
                total += RamUsageEstimator.SizeOf(dis);
            }

            return(total);
        }
示例#3
0
 private void OnGetCacheKeys(Events.GetCacheKeysEventArgs e)
 {
     e.CacheKeys.Add(this.CoreCacheKey);
 }