Move cache keys to Constants

This commit is contained in:
Tom Fulton
2014-04-04 17:09:42 -06:00
parent c883afc81f
commit 6cc91e4359
3 changed files with 11 additions and 4 deletions
@@ -5,5 +5,9 @@
public const string PropertyEditorAlias = "Imulus.Archetype";
public const string PreValueAlias = "archetypeConfig";
public const string CacheKey_DataTypeByGuid = "";
public const string CacheKey_PreValueFromDataTypeId = "Archetype_GetArchetypePreValueFromDataTypeId_";
}
}
@@ -22,8 +22,11 @@ namespace Archetype.Umbraco.Events
void ExpirePreValueCache(IDataTypeService sender, global::Umbraco.Core.Events.SaveEventArgs<IDataTypeDefinition> e)
{
ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheItem("Archetype_GetArchetypePreValueFromDataTypeId_" + e.SavedEntities.First().Id);
ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheItem("Archetype_GetArchetypePreValueFromDataTypeId_GetPropertyEditorAlias_"+ e.SavedEntities.First().Id);
foreach (var dataType in e.SavedEntities)
{
ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheItem(Constants.CacheKey_PreValueFromDataTypeId + dataType.Id);
ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheItem(Constants.CacheKey_DataTypeByGuid + dataType.Key);
}
}
}
}
@@ -95,7 +95,7 @@ namespace Archetype.Umbraco.PropertyConverters
private ArchetypePreValue GetArchetypePreValueFromDataTypeId(int dataTypeId, IDictionary<Guid, IDataTypeDefinition> dataTypeCache)
{
return ApplicationContext.Current.ApplicationCache.RuntimeCache.GetCacheItem(
"Archetype_GetArchetypePreValueFromDataTypeId_" + dataTypeId,
Constants.CacheKey_PreValueFromDataTypeId + dataTypeId,
() =>
{
var preValues = Services.DataTypeService.GetPreValuesCollectionByDataTypeId(dataTypeId);
@@ -122,7 +122,7 @@ namespace Archetype.Umbraco.PropertyConverters
private IDataTypeDefinition GetDataTypeByGuid(Guid guid)
{
return (IDataTypeDefinition) ApplicationContext.Current.ApplicationCache.RuntimeCache.GetCacheItem(
"Archetype_GetDataTypeDefinitionById_" + guid,
Constants.CacheKey_DataTypeByGuid + guid,
() => Services.DataTypeService.GetDataTypeDefinitionById(guid));
}
}