Caching RecycleBinSmells

This commit is contained in:
Elitsa Marinovska
2021-03-25 11:49:38 +01:00
parent bfc3068d6a
commit d2a26bf4da
6 changed files with 31 additions and 2 deletions

View File

@@ -17,5 +17,8 @@
public const string UserAllMediaStartNodesPrefix = "AllMediaStartNodes";
public const string UserMediaStartNodePathsPrefix = "MediaStartNodePaths";
public const string UserContentStartNodePathsPrefix = "ContentStartNodePaths";
public const string ContentRecycleBinCacheKey = "recycleBin_content";
public const string MediaRecycleBinCacheKey = "recycleBin_media";
}
}

View File

@@ -46,6 +46,7 @@ namespace Umbraco.Web.Cache
public override void Refresh(JsonPayload[] payloads)
{
AppCaches.RuntimeCache.ClearOfType<PublicAccessEntry>();
AppCaches.RuntimeCache.ClearByKey(CacheKeys.ContentRecycleBinCacheKey);
var idsRemoved = new HashSet<int>();
var isolatedCache = AppCaches.IsolatedCaches.GetOrCreate<IContent>();

View File

@@ -48,6 +48,7 @@ namespace Umbraco.Web.Cache
if (anythingChanged)
{
Current.AppCaches.ClearPartialViewCache();
AppCaches.RuntimeCache.ClearByKey(CacheKeys.MediaRecycleBinCacheKey);
var mediaCache = AppCaches.IsolatedCaches.Get<IMedia>();

View File

@@ -44,6 +44,8 @@ namespace Umbraco.Web.Trees
protected override bool RecycleBinSmells => Services.ContentService.RecycleBinSmells();
public override string RecycleBinSmellsCacheKey => CacheKeys.ContentRecycleBinCacheKey;
private int[] _userStartNodes;
protected override int[] UserStartNodes

View File

@@ -26,9 +26,11 @@ namespace Umbraco.Web.Trees
{
public abstract class ContentTreeControllerBase : TreeController
{
private readonly AppCaches _appCaches;
protected ContentTreeControllerBase(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoHelper umbracoHelper) : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper)
{
_appCaches = appCaches;
}
protected ContentTreeControllerBase()
@@ -148,6 +150,11 @@ namespace Umbraco.Web.Trees
/// </summary>
protected abstract bool RecycleBinSmells { get; }
/// <summary>
/// Gets the name of the recycle bin cache key.
/// </summary>
public abstract string RecycleBinSmellsCacheKey { get; }
/// <summary>
/// Returns the user's start node for this tree
/// </summary>
@@ -327,15 +334,29 @@ namespace Umbraco.Web.Trees
//and for some reason when there are no dashboards, this parameter is missing
if (IsDialog(queryStrings) == false && id == Constants.System.RootString && queryStrings.HasKey("application"))
{
var cache = _appCaches.RuntimeCache;
var hasChildren = cache.GetCacheItem<bool?>(RecycleBinSmellsCacheKey);
bool recycleBinSmells;
if (!(hasChildren is null))
{
recycleBinSmells = (bool) hasChildren;
}
else
{
recycleBinSmells = RecycleBinSmells;
cache.InsertCacheItem<bool>(RecycleBinSmellsCacheKey, () => recycleBinSmells);
}
nodes.Add(CreateTreeNode(
RecycleBinId.ToInvariantString(),
id,
queryStrings,
Services.TextService.Localize("general/recycleBin"),
"icon-trash",
RecycleBinSmells,
recycleBinSmells,
queryStrings.GetRequiredValue<string>("application") + TreeAlias.EnsureStartsWith('/') + "/recyclebin"));
}
return nodes;

View File

@@ -47,6 +47,7 @@ namespace Umbraco.Web.Trees
protected override int RecycleBinId => Constants.System.RecycleBinMedia;
protected override bool RecycleBinSmells => Services.MediaService.RecycleBinSmells();
public override string RecycleBinSmellsCacheKey => CacheKeys.MediaRecycleBinCacheKey;
private int[] _userStartNodes;
protected override int[] UserStartNodes