Пример #1
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);
        }
Пример #2
0
 public void Insert(object key, CacheItem value)
 {
     Logger.Log(
         "Inserting item '" + value + "' against key '" + key + "'.",
         Microsoft.Extensions.Logging.LogLevel.Trace
         );
     _nCache.Insert(key.ToString(), value);
 }
Пример #3
0
 public void Insert(string key, object value)
 {
     Alachisoft.NCache.Web.Caching.Cache cache = (Alachisoft.NCache.Web.Caching.Cache)_caches[_primaryCache];
     if (cache != null)
     {
         cache.Insert(key, TagUtil.CreateTaggedCacheItem(value));
     }
 }
Пример #4
0
        public void Insert(string sessionId, string key, object value, CacheDependency dependency, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority)
        {
            Alachisoft.NCache.Web.Caching.Cache cache = null;
            object obj = null;

            GetCache(sessionId, key, out obj, "", "", out cache, false);
            if (cache != null)
            {
                cache.Insert(key, TagUtil.CreateTaggedCacheItem(value, dependency, absoluteExpiration, slidingExpiration, priority));
            }
        }
Пример #5
0
        public void Insert(string sessionId, string key, object value, bool enableRetry)
        {
            Alachisoft.NCache.Web.Caching.Cache cache = null;
            object obj = null;

            GetCache(sessionId, key, out obj, "", "", out cache, false);
            if (cache != null)
            {
                cache.Insert(key, TagUtil.CreateTaggedCacheItem(value));
            }
        }
Пример #6
0
        public void Insert(string sessionId, string key, CacheItem item, LockHandle lockHandle, bool releaseLock, bool enableRetry)
        {
            Alachisoft.NCache.Web.Caching.Cache cache = null;
            object obj = null;

            _sync.AcquireReaderLock(Timeout.Infinite);
            try
            {
                GetCache(sessionId, key, out obj, "", "", out cache, false);
                if (cache != null)
                {
                    item.Tags = new Runtime.Caching.Tag[] { new Runtime.Caching.Tag(TagUtil.SESSION_TAG) };
                    cache.Insert(key, item, lockHandle, releaseLock);
                }
            }
            finally
            {
                _sync.ReleaseReaderLock();
            }
        }
Пример #7
0
        public void Insert(string sessionId, string key, CacheItem item, string group, string subGroup)
        {
            Alachisoft.NCache.Web.Caching.Cache cache = null;
            object obj = null;

            _sync.AcquireReaderLock(Timeout.Infinite);
            try
            {
                GetCache(sessionId, key, out obj, group, subGroup, out cache, false);
                if (cache != null)
                {
                    item.Group    = group;
                    item.SubGroup = subGroup;
                    item.Tags     = new Runtime.Caching.Tag[] { new Runtime.Caching.Tag(TagUtil.SESSION_TAG) };

                    cache.Insert(key, item, DSWriteOption.None, null);
                }
            }
            finally
            {
                _sync.ReleaseReaderLock();
            }
        }
Пример #8
0
 public void Insert(string key, object value, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority)
 {
     _cache.Insert(key, value, absoluteExpiration, slidingExpiration, priority);
 }
Пример #9
0
 public void Insert(string sessionId, string key, object value, CacheDependency dependency, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority)
 {
     _cache.Insert(key, TagUtil.CreateTaggedCacheItem(value, dependency, absoluteExpiration, slidingExpiration, priority));
 }