changes all instances accessing cache by key "contentItem" to use CacheKeys.ContentItemCache and replaces

all of it's cache usages with the ApplicationContext.Current.ApplicationCache. Obsoletes a couple of methods
that are not used.
This commit is contained in:
Shannon Deminick
2013-04-03 22:34:40 +06:00
parent 23525300bb
commit e14d3fd379
8 changed files with 77 additions and 40 deletions

View File

@@ -6,6 +6,8 @@ namespace Umbraco.Core.Cache
/// </summary>
public static class CacheKeys
{
public const string ContentItemCacheKey = "contentItem";
public const string MediaCacheKey = "UL_GetMedia";
public const string MacroCacheKey = "UmbracoMacroCache";

View File

@@ -26,6 +26,7 @@ namespace Umbraco.Core.Cache
public abstract T GetCacheItem<T>(string cacheKey, CacheItemRemovedCallback refreshAction, TimeSpan timeout, Func<T> getCacheItem);
public abstract T GetCacheItem<T>(string cacheKey, CacheItemPriority priority, CacheItemRemovedCallback refreshAction, TimeSpan timeout, Func<T> getCacheItem);
public abstract T GetCacheItem<T>(string cacheKey, CacheItemPriority priority, CacheItemRemovedCallback refreshAction, CacheDependency cacheDependency, TimeSpan timeout, Func<T> getCacheItem);
public abstract void InsertCacheItem<T>(string cacheKey, CacheItemPriority priority, Func<T> getCacheItem);
public abstract void InsertCacheItem<T>(string cacheKey, CacheItemPriority priority, TimeSpan timeout, Func<T> getCacheItem);
public abstract void InsertCacheItem<T>(string cacheKey, CacheItemPriority priority, CacheDependency cacheDependency, TimeSpan timeout, Func<T> getCacheItem);
public abstract void InsertCacheItem<T>(string cacheKey, CacheItemPriority priority, CacheItemRemovedCallback refreshAction, CacheDependency cacheDependency, TimeSpan? timeout, Func<T> getCacheItem);

View File

@@ -277,6 +277,20 @@ namespace Umbraco.Core.Cache
return result.TryConvertTo<TT>().Result;
}
/// <summary>
/// Inserts an item into the cache, if it already exists in the cache it will be replaced
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="cacheKey"></param>
/// <param name="priority"></param>
/// <param name="getCacheItem"></param>
public override void InsertCacheItem<T>(string cacheKey,
CacheItemPriority priority,
Func<T> getCacheItem)
{
InsertCacheItem(cacheKey, priority, null, null, null, getCacheItem);
}
/// <summary>
/// Inserts an item into the cache, if it already exists in the cache it will be replaced
/// </summary>

View File

@@ -66,6 +66,10 @@ namespace Umbraco.Core.Cache
return getCacheItem();
}
public override void InsertCacheItem<T>(string cacheKey, CacheItemPriority priority, Func<T> getCacheItem)
{
}
public override void InsertCacheItem<T>(string cacheKey, CacheItemPriority priority, TimeSpan timeout, Func<T> getCacheItem)
{
}

View File

@@ -272,6 +272,27 @@ namespace Umbraco.Core
return _httpCache.GetCacheItem<TT>(cacheKey, priority, refreshAction, cacheDependency, timeout, getCacheItem);
}
}
/// <summary>
/// Inserts an item into the cache, if it already exists in the cache it will be replaced
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="cacheKey"></param>
/// <param name="priority"></param>
/// <param name="getCacheItem"></param>
public void InsertCacheItem<T>(string cacheKey,
CacheItemPriority priority,
Func<T> getCacheItem)
{
if (!_enableCache)
{
_nullCache.InsertCacheItem<T>(cacheKey, priority, getCacheItem);
}
else
{
_httpCache.InsertCacheItem<T>(cacheKey, priority, getCacheItem);
}
}
/// <summary>
/// Inserts an item into the cache, if it already exists in the cache it will be replaced

View File

@@ -4,6 +4,8 @@ using System.Collections.Specialized;
using System.Globalization;
using System.Linq;
using System.Web;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Media;
using umbraco;
@@ -72,12 +74,8 @@ namespace Umbraco.Web.Media
private static object GetContentFromCache(int nodeIdInt, string field)
{
var context = HttpContext.Current;
if (context == null)
return string.Empty;
var content = context.Cache[String.Format("contentItem{0}_{1}", nodeIdInt.ToString(CultureInfo.InvariantCulture), field)];
var content = ApplicationContext.Current.ApplicationCache.GetCacheItem<object>(
string.Format("{0}{1}_{2}", CacheKeys.ContentItemCacheKey, nodeIdInt.ToString(CultureInfo.InvariantCulture), field));
return content;
}
}

View File

@@ -497,23 +497,9 @@ namespace umbraco
ClearContextCache();
}
// clear cached field values
if (HttpContext.Current != null)
{
System.Web.Caching.Cache httpCache = HttpContext.Current.Cache;
string cachedFieldKeyStart = String.Format("contentItem{0}_", d.Id);
var foundKeys = new List<string>();
foreach (DictionaryEntry cacheItem in httpCache)
{
string key = cacheItem.Key.ToString();
if (key.StartsWith(cachedFieldKeyStart))
foundKeys.Add(key);
}
foreach (string foundKey in foundKeys)
{
httpCache.Remove(foundKey);
}
}
var cachedFieldKeyStart = string.Format("{0}{1}_", CacheKeys.ContentItemCacheKey, d.Id);
ApplicationContext.Current.ApplicationCache.ClearCacheByKeySearch(cachedFieldKeyStart);
Action.RunActionHandlers(d, ActionPublish.Instance);
FireAfterUpdateDocumentCache(d, e);

View File

@@ -5,8 +5,11 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Caching;
using System.Web.UI;
using System.Xml;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Macros;
using Umbraco.Web;
using Umbraco.Web.PublishedCache;
@@ -229,29 +232,31 @@ namespace umbraco.presentation.templateControls
return item.TextIfEmpty;
}
/// <summary>
/// Gets the field content from database instead of the published XML via the APIs.
/// </summary>
/// <param name="nodeIdInt">The node id.</param>
/// <param name="currentField">The field that should be fetched.</param>
/// <returns>The contents of the <paramref name="currentField"/> from the <paramref name="nodeIdInt"/> content object</returns>
/// <summary>
/// Gets the field content from database instead of the published XML via the APIs.
/// </summary>
/// <param name="itemAttributes"></param>
/// <param name="nodeIdInt">The node id.</param>
/// <param name="currentField">The field that should be fetched.</param>
/// <returns>The contents of the <paramref name="currentField"/> from the <paramref name="nodeIdInt"/> content object</returns>
[Obsolete("This is no longer used in the codebase and will be removed in future versions")]
protected virtual string GetContentFromDatabase(AttributeCollectionAdapter itemAttributes, int nodeIdInt, string currentField)
{
Content c = new Content(nodeIdInt);
var c = new Content(nodeIdInt);
Property property = c.getProperty(currentField);
var property = c.getProperty(currentField);
if (property == null)
throw new ArgumentException(String.Format("Could not find property {0} of node {1}.", currentField, nodeIdInt));
item umbItem = new item(property.Value.ToString(), itemAttributes);
string tempElementContent = umbItem.FieldContent;
var umbItem = new item(property.Value.ToString(), itemAttributes);
var tempElementContent = umbItem.FieldContent;
// If the current content object is a document object, we'll only output it if it's published
if (c.nodeObjectType == cms.businesslogic.web.Document._objectType)
if (c.nodeObjectType == Document._objectType)
{
try
{
Document d = (Document)c;
var d = (Document)c;
if (!d.Published)
tempElementContent = "";
}
@@ -259,9 +264,13 @@ namespace umbraco.presentation.templateControls
}
// Add the content to the cache
if (!String.IsNullOrEmpty(tempElementContent))
HttpContext.Current.Cache.Insert(String.Format("contentItem{0}_{1}", nodeIdInt.ToString(), currentField), tempElementContent);
return tempElementContent;
if (!string.IsNullOrEmpty(tempElementContent))
{
ApplicationContext.Current.ApplicationCache.InsertCacheItem(
string.Format("{0}{1}_{2}", CacheKeys.ContentItemCacheKey, nodeIdInt, currentField),
CacheItemPriority.Default, () => tempElementContent);
}
return tempElementContent;
}
/// <summary>
@@ -269,10 +278,12 @@ namespace umbraco.presentation.templateControls
/// </summary>
/// <param name="nodeIdInt">The node id.</param>
/// <param name="field">The field.</param>
/// <returns>The cached contents of the <paramref name="currentField"/> from the <paramref name="nodeIdInt"/> content object</returns>
/// <returns>The cached contents of the <paramref name="field"/> from the <paramref name="nodeIdInt"/> content object</returns>
[Obsolete("This is no longer used in the codebase and will be removed in future versions")]
protected virtual object GetContentFromCache(int nodeIdInt, string field)
{
object content = HttpContext.Current.Cache[String.Format("contentItem{0}_{1}", nodeIdInt.ToString(), field.ToString())];
var content = ApplicationContext.Current.ApplicationCache.GetCacheItem<object>(
string.Format("{0}{1}_{2}", CacheKeys.ContentItemCacheKey, nodeIdInt, field));
return content;
}
}