Working with caching
Information on how to insert and delete from the runtime cache
Scenario
Example
TagService
using System;
using System.Collections.Generic;
using Umbraco.Cms.Core.Cache;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.PublishedCache;
using Umbraco.Extensions;
namespace Doccers.Core.Services.Implement;
public class CacheTagService : ICacheTagService
{
private readonly ITagQuery _tagQuery;
private readonly IAppPolicyCache _runtimeCache;
public CacheTagService(ITagQuery tagQuery, AppCaches appCaches)
{
_tagQuery = tagQuery;
// Get the RuntimeCache from appCaches
// and assign to our private field.
_runtimeCache = appCaches.RuntimeCache;
}
public IEnumerable<TagModel> GetAll(
string group,
string cacheKey,
TimeSpan? timeout = null)
{
// GetCacheItem will automatically insert the object
// into cache if it doesn't exist.
return _runtimeCache.GetCacheItem(cacheKey, () =>
{
return _tagQuery.GetAllTags(group);
}, timeout);
}
}API


Clearing cache on publish
Last updated
Was this helpful?