Example #1
0
        private CachedOrds GetCachedOrds(AtomicReaderContext context)
        {
            object cacheKey = context.Reader.CoreCacheKey;

#if FEATURE_CONDITIONALWEAKTABLE_ENUMERATOR
            return(ordsCache.GetValue(cacheKey, (cacheKey) => new CachedOrds(source.GetReader(context), context.Reader.MaxDoc)));
#else
            CachedOrds ords;
            syncLock.EnterReadLock();
            try
            {
                if (ordsCache.TryGetValue(cacheKey, out ords))
                {
                    return(ords);
                }
            }
            finally
            {
                syncLock.ExitReadLock();
            }

            ords = new CachedOrds(source.GetReader(context), context.Reader.MaxDoc);
            syncLock.EnterWriteLock();
            try
            {
                ordsCache[cacheKey] = ords;
            }
            finally
            {
                syncLock.ExitWriteLock();
            }

            return(ords);
#endif
        }
Example #2
0
        private CachedOrds GetCachedOrds(AtomicReaderContext context)
        {
            // LUCENENET NOTE: Since ConditionalWeakTable doesn't synchronize on enumeration in the RamBytesUsed() method,
            // the lock is still required here despite it being a threadsafe collection.
            UninterruptableMonitor.Enter(syncLock);
            try
            {
                object cacheKey = context.Reader.CoreCacheKey;
                if (!ordsCache.TryGetValue(cacheKey, out CachedOrds ords))
                {
                    ords = new CachedOrds(source.GetReader(context), context.Reader.MaxDoc);

                    // LUCENENET specific: Since this is the only thread that can modify ordsCache
                    // and we just checked that the value doesn't exist above, we can simplify this to Add()
                    // which also means we don't need conditional compilation because ConditionalWeakTable
                    // doesn't support this[index].
                    ordsCache.Add(cacheKey, ords);
                }
                return(ords);
            }
            finally
            {
                UninterruptableMonitor.Exit(syncLock);
            }
        }
Example #3
0
        private CachedOrds GetCachedOrds(AtomicReaderContext context)
        {
            // LUCENENET NOTE: Since ConditionalWeakTable doesn't synchronize on enumeration in the RamBytesUsed() method,
            // the lock is still required here despite it being a threadsafe collection.
            UninterruptableMonitor.Enter(syncLock);
            try
            {
                object cacheKey = context.Reader.CoreCacheKey;
                if (!ordsCache.TryGetValue(cacheKey, out CachedOrds ords))
                {
                    ords = new CachedOrds(source.GetReader(context), context.Reader.MaxDoc);

                    // LUCENENET specific: Since this is the only thread that can modify ordsCache
                    // and we just checked that the value doesn't exist above, we can simplify this to Add()
                    // which also means we don't need conditional compilation because ConditionalWeakTable
                    // doesn't support this[index].
                    ordsCache.Add(cacheKey, ords);
#if !FEATURE_CONDITIONALWEAKTABLE_ENUMERATOR
                    // LUCENENET specific: Add weak event handler for .NET Standard 2.0 and .NET Framework, since we don't have an enumerator to use
                    context.Reader.SubscribeToGetCacheKeysEvent(eventAggregator.GetEvent <Events.GetCacheKeysEvent>());
#endif
                }
                return(ords);
            }
            finally
            {
                UninterruptableMonitor.Exit(syncLock);
            }
        }
        private CachedOrds GetCachedOrds(AtomicReaderContext context)
        {
            lock (this)
            {
                object cacheKey = context.Reader.CoreCacheKey;
                if (!ordsCache.TryGetValue(cacheKey, out CachedOrds ords) || ords == null)
                {
                    ords = new CachedOrds(source.GetReader(context), context.Reader.MaxDoc);
                    ordsCache[cacheKey] = ords;
                }

                return(ords);
            }
        }
        private CachedOrds GetCachedOrds(AtomicReaderContext context)
        {
            lock (this)
            {
                object cacheKey = context.Reader.CoreCacheKey;
                CachedOrds ords = ordsCache[cacheKey];
                if (ords == null)
                {
                    ords = new CachedOrds(source.GetReader(context), context.Reader.MaxDoc);
                    ordsCache[cacheKey] = ords;
                }

                return ords;
            }
        }
        private CachedOrds GetCachedOrds(AtomicReaderContext context)
        {
            object cacheKey = context.Reader.CoreCacheKey;

#if FEATURE_CONDITIONALWEAKTABLE_ENUMERATOR
            return(ordsCache.GetValue(cacheKey, (cacheKey) => new CachedOrds(source.GetReader(context), context.Reader.MaxDoc)));
#else
            lock (this)
            {
                if (!ordsCache.TryGetValue(cacheKey, out CachedOrds ords) || ords == null)
                {
                    ords = new CachedOrds(source.GetReader(context), context.Reader.MaxDoc);
                    ordsCache[cacheKey] = ords;
                }

                return(ords);
            }
#endif
        }
        public override OrdinalsSegmentReader GetReader(AtomicReaderContext context)
        {
            CachedOrds cachedOrds = GetCachedOrds(context);

            return(new OrdinalsSegmentReaderAnonymousInnerClassHelper(this, cachedOrds));
        }
Example #8
0
 public OrdinalsSegmentReaderAnonymousClass(CachedOrds cachedOrds)
 {
     this.cachedOrds = cachedOrds;
 }
Example #9
0
 public OrdinalsSegmentReaderAnonymousInnerClassHelper(CachedOrds cachedOrds)
 {
     this.cachedOrds = cachedOrds;
 }