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); }
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); }
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)); } }
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)); } }
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)); } }
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(); } }
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(); } }
public void Insert(string key, object value, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority) { _cache.Insert(key, value, absoluteExpiration, slidingExpiration, priority); }
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)); }