예제 #1
0
        // <summary>
        // lookup service
        // </summary>
        // <returns> true if cache hit, false if cache miss </returns>
        private bool TryInternalCacheLookup(QueryCacheKey queryCacheKey, out QueryCacheEntry queryCacheEntry)
        {
            DebugCheck.NotNull(queryCacheKey);

            queryCacheEntry = null;

            var bHit = false;

            //
            // lock the cache for the minimal possible period
            //
            lock (_cacheDataLock)
            {
                bHit = _cacheData.TryGetValue(queryCacheKey, out queryCacheEntry);
            }

            //
            // if cache hit
            //
            if (bHit)
            {
                //
                // update hit mark in cache key
                //
                queryCacheEntry.QueryCacheKey.UpdateHit();
            }

            return(bHit);
        }
예제 #2
0
        // <summary>
        // Adds new entry to the cache using "abstract" cache context and
        // value; returns an existing entry if the key is already in the
        // dictionary.
        // </summary>
        // <param name="outQueryCacheEntry"> The existing entry in the dicitionary if already there; inQueryCacheEntry if none was found and inQueryCacheEntry was added instead. </param>
        // <returns> true if the output entry was already found; false if it had to be added. </returns>
        internal bool TryLookupAndAdd(QueryCacheEntry inQueryCacheEntry, out QueryCacheEntry outQueryCacheEntry)
        {
            DebugCheck.NotNull(inQueryCacheEntry);

            outQueryCacheEntry = null;

            lock (_cacheDataLock)
            {
                if (!_cacheData.TryGetValue(inQueryCacheEntry.QueryCacheKey, out outQueryCacheEntry))
                {
                    //
                    // add entry to cache data
                    //
                    _cacheData.Add(inQueryCacheEntry.QueryCacheKey, inQueryCacheEntry);
                    if (_cacheData.Count > _sweepingTriggerHighMark)
                    {
                        _evictionTimer.Start();
                    }

                    return(false);
                }
                else
                {
                    outQueryCacheEntry.QueryCacheKey.UpdateHit();

                    return(true);
                }
            }
        }
        internal bool TryCacheLookup <TK, TE>(TK key, out TE value) where TK : QueryCacheKey
        {
            value = default(TE);
            QueryCacheEntry queryCacheEntry = (QueryCacheEntry)null;
            bool            flag            = this.TryInternalCacheLookup((QueryCacheKey)key, out queryCacheEntry);

            if (flag)
            {
                value = (TE)queryCacheEntry.GetTarget();
            }
            return(flag);
        }
        private bool TryInternalCacheLookup(
            QueryCacheKey queryCacheKey,
            out QueryCacheEntry queryCacheEntry)
        {
            queryCacheEntry = (QueryCacheEntry)null;
            bool flag = false;

            lock (this._cacheDataLock)
                flag = this._cacheData.TryGetValue(queryCacheKey, out queryCacheEntry);
            if (flag)
            {
                queryCacheEntry.QueryCacheKey.UpdateHit();
            }
            return(flag);
        }
 internal bool TryLookupAndAdd(
     QueryCacheEntry inQueryCacheEntry,
     out QueryCacheEntry outQueryCacheEntry)
 {
     outQueryCacheEntry = (QueryCacheEntry)null;
     lock (this._cacheDataLock)
     {
         if (!this._cacheData.TryGetValue(inQueryCacheEntry.QueryCacheKey, out outQueryCacheEntry))
         {
             this._cacheData.Add(inQueryCacheEntry.QueryCacheKey, inQueryCacheEntry);
             if (this._cacheData.Count > this._sweepingTriggerHighMark)
             {
                 this._evictionTimer.Start();
             }
             return(false);
         }
         outQueryCacheEntry.QueryCacheKey.UpdateHit();
         return(true);
     }
 }
예제 #6
0
        // <summary>
        // Lookup service for a cached value.
        // </summary>
        internal bool TryCacheLookup <TK, TE>(TK key, out TE value)
            where TK : QueryCacheKey
        {
            DebugCheck.NotNull(key);

            value = default(TE);

            //
            // invoke internal lookup
            //
            QueryCacheEntry qEntry = null;
            var             bHit   = TryInternalCacheLookup(key, out qEntry);

            //
            // if it is a hit, 'extract' the entry strong type cache value
            //
            if (bHit)
            {
                value = (TE)qEntry.GetTarget();
            }

            return(bHit);
        }