Permalink
Browse files

Increasing the max size and mentioning to the config files for the "P…

…age placeholders" cache; refactoring
  • Loading branch information...
napernik committed Sep 29, 2017
1 parent a7e09cb commit 00010ee663863728ca80a4c7ec8db6523c76487a
@@ -76,7 +76,7 @@ public class Cache
private bool _enabled = true;
private bool _clearOnFlush = true;
private int _maxSize;
private int _defaultMaximumSize;
private readonly int _defaultMaximumSize;
/// <exclude />
@@ -101,21 +101,15 @@ public Cache(string name, int defaultMaximumSize)
/// <exclude />
public bool Enabled
{
get { return _enabled; }
}
public bool Enabled => _enabled;
/// <exclude />
public string Name { get; private set; }
public string Name { get; }
/// <exclude />
protected object Get(object key)
{
return _table[key];
}
protected object Get(object key) => _table[key];
/// <exclude />
@@ -130,7 +124,7 @@ protected void Add(object key, object value)
{
if (_maxSize != -1 && _table.Count > _maxSize)
{
Log.LogWarning("Cache", "Clearing cache '{0}' as it exceeded maximum size {1} elements. Edit configuration file to increase the cache size.", Name, _maxSize);
Log.LogWarning("Cache", $"Clearing cache '{Name}' as it exceeded maximum size {_maxSize} elements. Edit configuration file /App_Data/Composite/Composite.config to increase the cache size.");
_table.Clear();
}
@@ -6,7 +6,6 @@
using Composite.Core.Linq;
using Composite.Data.Caching;
using Composite.Data.Foundation;
using Composite.Core.Extensions;
using Composite.Core.Types;
using Composite.Data.Types;
@@ -39,7 +38,7 @@ public PageStructureRecord(IPageStructure ps)
private static readonly int PageCacheSize = 5000;
private static readonly int PageStructureCacheSize = 3000;
private static readonly int ChildrenCacheSize = 2000;
private static readonly int PagePlaceholderCacheSize = 500;
private static readonly int PagePlaceholderCacheSize = 10000;
private static readonly Cache<string, IReadOnlyCollection<IPage>> _pageCache = new Cache<string, IReadOnlyCollection<IPage>>("Pages", PageCacheSize);
private static readonly Cache<string, ReadOnlyCollection<IPagePlaceholderContent>> _placeholderCache = new Cache<string, ReadOnlyCollection<IPagePlaceholderContent>>("Page placeholders", PagePlaceholderCacheSize);
@@ -301,7 +300,7 @@ private static PageStructureRecord GetPageStructureRecord(Guid pageId)
if (result == null)
{
Log.LogWarning(LogTitle, "No IPageStructure entries found for Page with Id '{0}'".FormatWith(pageId));
Log.LogWarning(LogTitle, $"No IPageStructure entries found for Page with Id '{pageId}'");
}
_pageStructureCache.Add(cacheKey, result);
@@ -348,13 +347,10 @@ private static void OnPageStoreChanged(object sender, StoreEventArgs storeEventA
private static void OnPageChanged(object sender, DataEventArgs args)
{
IPage page = args.Data as IPage;
if (page == null)
if (args.Data is IPage page)
{
return;
_pageCache.Remove(GetCacheKey(page.Id, page.DataSourceId));
}
_pageCache.Remove(GetCacheKey(page.Id, page.DataSourceId));
}
@@ -368,13 +364,10 @@ private static void OnPagePlaceholderStoreChanged(object sender, StoreEventArgs
private static void OnPagePlaceholderChanged(object sender, DataEventArgs args)
{
var placeHolder = args.Data as IPagePlaceholderContent;
if (placeHolder == null)
if (args.Data is IPagePlaceholderContent placeHolder)
{
return;
_placeholderCache.Remove(GetCacheKey(placeHolder.PageId, placeHolder.VersionId, placeHolder.DataSourceId));
}
_placeholderCache.Remove(GetCacheKey(placeHolder.PageId, placeHolder.VersionId, placeHolder.DataSourceId));
}
@@ -390,14 +383,11 @@ private static void OnPageStructureStoreChanged(object sender, StoreEventArgs st
private static void OnPageStructureChanged(object sender, DataEventArgs args)
{
var ps = args.Data as IPageStructure;
if (ps == null)
if (args.Data is IPageStructure pageStructure)
{
return;
_pageStructureCache.Remove(pageStructure.Id);
_childrenCache.Remove(pageStructure.ParentId);
}
_pageStructureCache.Remove(ps.Id);
_childrenCache.Remove(ps.ParentId);
}
private static IPage CreateWrapper(IPage page)
@@ -103,6 +103,7 @@
<add name="DataAccess" enabled="true" size="-1"/>
<add name="Pages" enabled="true" size="20000" />
<add name="Page structure" enabled="true" size="20000" />
<add name="Page placeholders" enabled="true" size="10000" />
<add name="Child pages" enabled="true" size="20000" />
<add name="Security permissions" enabled="true" size="1000" />
<add name="Resource strings" enabled="true" size="5000" />
@@ -98,6 +98,7 @@
<add name="DataAccess" enabled="true" size="-1"/>
<add name="Pages" enabled="true" size="20000" />
<add name="Page structure" enabled="true" size="20000" />
<add name="Page placeholders" enabled="true" size="10000" />
<add name="Child pages" enabled="true" size="20000" />
<add name="Security permissions" enabled="true" size="1000" />
<add name="Resource strings" enabled="true" size="5000" />

0 comments on commit 00010ee

Please sign in to comment.