コード例 #1
0
 public bool TryGetValue(object key, out object value)
 {
     Logger.Log(
         "Trying to get item against key '" + key + "'",
         Microsoft.Extensions.Logging.LogLevel.Trace
         );
     value = _nCache.Get(key.ToString());
     return(value != null);
 }
コード例 #2
0
        public async Task <Author> GetAuthor(int id)
        {
            _cache = NCache.InitializeCache("CacheName");
            var    cacheKey = "Key";
            Author author   = null;

            if (_cache != null)
            {
                author = _cache.Get(cacheKey) as Author;
            }
            if (author == null) //Data not available in the cache
            {
                //Write code here to fetch the author
                // object from the database
                if (author != null)
                {
                    if (_cache != null)
                    {
                        _cache.Insert(cacheKey, author, null,
                                      Alachisoft.NCache.Web.Caching.Cache.NoAbsoluteExpiration,
                                      TimeSpan.FromMinutes(10),
                                      Alachisoft.NCache.Runtime.
                                      CacheItemPriority.Default);
                    }
                }
            }
            return(author);
        }
コード例 #3
0
 public object Get(string key)
 {
     Alachisoft.NCache.Web.Caching.Cache cache = (Alachisoft.NCache.Web.Caching.Cache)_caches[_primaryCache];
     if (cache != null)
     {
         return(cache.Get(key));
     }
     else
     {
         return(null);
     }
 }
コード例 #4
0
 public object Get(string key, bool enableRetry)
 {
     return(_cache.Get(key));
 }
コード例 #5
0
        void GetCache(string sessionId, string key, out object value, string group, string subGroup, out Alachisoft.NCache.Web.Caching.Cache cache, bool isGet, ref LockHandle lockHandle, bool acquireLock)
        {
            value = null;

            //Implementation For Raiynair cookieless robots
            string sidPrefix = string.Empty;

            sidPrefix = sessionId.Substring(0, 4);
            if (!_settings.PrimaryCache.Contains(sidPrefix) && _isSessionCookieless)
            {
                _isSessionCookieless = false;
                cache = null;
                return;
            }
            _isSessionCookieless = false;

            cache = _caches[GetCache(sessionId)] as Alachisoft.NCache.Web.Caching.Cache;

            if (cache != null)
            {
                if (isGet)
                {
                    value = cache.Get(key, Alachisoft.NCache.Web.Caching.Cache.NoLockExpiration, ref lockHandle, acquireLock);
                }
            }
            else
            {
                if (_currentSessionCache == null || _currentSessionCache == string.Empty)
                {
                    IDictionaryEnumerator cacheDic = _caches.GetEnumerator();
                    do
                    {
                        /// This code will ensure that primary cache is used first to be lookedin.
                        if (cache == null)
                        {
                            cache = _caches[_primaryCache] as Alachisoft.NCache.Web.Caching.Cache;
                        }
                        else
                        {
                            cache = (Alachisoft.NCache.Web.Caching.Cache)cacheDic.Value;// select the cache from enumerator.
                            // primary cache is already traversed so no need to do it again.
                            if (cache.ToString().Equals(_primaryCache))
                            {
                                continue;
                            }
                        }

                        if (isGet)
                        {
                            value = cache.Get(key, Alachisoft.NCache.Web.Caching.Cache.NoLockExpiration, ref lockHandle, acquireLock);
                        }
                        else
                        {
                            if (cache.Contains(key))
                            {
                                value = new object();
                                break;
                            }
                        }
                    } while (cacheDic.MoveNext() && value == null);

                    if (value != null) // value was found from one of the caches. so use that cache for all further operations during this HTTP request.
                    {
                        _currentSessionCache = cache.ToString();
                    }
                    else// value wasn't found from any of the caches. thus use hte primary cache for all further operations.
                    {
                        _currentSessionCache = _primaryCache;
                    }
                }
                else
                {
                    cache = _caches[_currentSessionCache] as Alachisoft.NCache.Web.Caching.Cache;
                    if (isGet)
                    {
                        value = cache.Get(key, Alachisoft.NCache.Web.Caching.Cache.NoLockExpiration, ref lockHandle, acquireLock);
                    }
                }
            }
        }
コード例 #6
0
        public object Get(string sessionId, string key, string group, string subGroup)
        {
            CacheItemVersion version = null;

            return(_cache.Get(key, DSReadOption.None, ref version));
        }