November Happy Hour will be moved to Thursday December 5th.
AI OnAI Off
November Happy Hour will be moved to Thursday December 5th.
Hi Quan,
If you cache the object depend on IContentCacheKeyCreator.VersionKey, then you will have to make sure that the entry exists in the cache first before inserting the record, otherwise the object will not be cached. The entry for IContentCacheKeyCreator.VersionKey will be removed if a content is updated on a remote server, so you'll need to call IContentCacheVersion.Version to ensure the entry is present. Could you please try to change your code to this and keep us updated of the result:
public class EPiServerCache : ICache { private readonly string[] _cacheDependencyKeys; private readonly ISynchronizedObjectInstanceCache _objectInstanceCache; private readonly IContentCacheVersion _contentCacheVersion; public EPiServerCache(ISynchronizedObjectInstanceCache objectInstanceCache, IContentCacheKeyCreator cacheKeyCreator, IContentCacheVersion contentCacheVersion) { _cacheDependencyKeys = new[] { cacheKeyCreator.VersionKey }; _objectInstanceCache = objectInstanceCache; _contentCacheVersion = contentCacheVersion; } public T Get<T>(string key) { T cacheItem; try { cacheItem = (T)_objectInstanceCache.Get(key); } catch (Exception) { cacheItem = default(T); } return cacheItem; } public void Add<T>(T objectToCache, string key, TimeSpan expiration) { // IContentCacheKeyCreator.VersionKey must exists in the cache. Otherwise // the entries are not cached (the key is removed when a remote server content is updated). // Version call ensures that the key is present var version = _contentCacheVersion.Version; var evictionPolicy = new CacheEvictionPolicy(expiration, CacheTimeoutType.Absolute, _cacheDependencyKeys); _objectInstanceCache.Insert(key, objectToCache, evictionPolicy); } public bool Exists(string key) { return (_objectInstanceCache.Get(key) != null); } public void Clear() { _objectInstanceCache.Clear(); } public void Remove(string key) { _objectInstanceCache.Remove(key); } }
Thanks,
Linh Doan
Hi guys,
Our customer are using hosting service of DXC. Recently, we have the issue regarding the output cache. Some objects that we added to mem cache seem always return directly (not from cache). Do you have any idea for this issue?
Here are my code to implement object cache :