Adding support for fetching of element descriptors from the blue print element harvester.

The problem before this change was that the cache manager would cache an empty list of elements when trying to locate a blueprint element without specifying a content item.
The VaryByParam property allows additional control over the cache key.
This commit is contained in:
Sipke Schoorstra
2014-11-21 23:57:26 -08:00
parent 06ebab41fe
commit 1a9e5f4681
4 changed files with 8 additions and 6 deletions

View File

@@ -93,7 +93,7 @@ namespace Orchard.Layouts.Framework.Display {
var dictionary = new Dictionary<string, object> {
{"Element", element},
{"Elements", children},
{"ContentItem", content.ContentItem}
{"ContentItem", content != null ? content.ContentItem : default(ContentItem)}
};
if (elementState != null) {

View File

@@ -28,8 +28,8 @@ namespace Orchard.Layouts.Providers {
var blueprints = _elementBlueprintService.Value.GetBlueprints().ToArray();
var query =
from blueprint in blueprints
let describeContext = DescribeElementsContext.Empty
from blueprint in blueprints
let describeContext = new DescribeElementsContext { Content = context.Content, CacheVaryParam = "Blueprints"}
let baseElementDescriptor = _elementManager.Value.GetElementDescriptorByTypeName(describeContext, blueprint.BaseElementTypeName)
let baseElement = _elementManager.Value.ActivateElement(baseElementDescriptor)
select new ElementDescriptor(

View File

@@ -3,6 +3,8 @@ using Orchard.ContentManagement;
namespace Orchard.Layouts.Services {
public class DescribeElementsContext {
public IContent Content { get; set; }
public static DescribeElementsContext Empty = new DescribeElementsContext();
public string CacheVaryParam { get; set; }
public static readonly DescribeElementsContext Empty = new DescribeElementsContext();
}
}

View File

@@ -37,7 +37,7 @@ namespace Orchard.Layouts.Services {
public IEnumerable<ElementDescriptor> DescribeElements(DescribeElementsContext context) {
var contentType = context.Content != null ? context.Content.ContentItem.ContentType : default(string);
var cacheKey = String.Format("LayoutElementTypes-{0}", contentType ?? "AnyType");
var cacheKey = String.Format("LayoutElementTypes-{0}-{1}", contentType ?? "AnyType", context.CacheVaryParam);
return _cacheManager.Get(cacheKey, acquireContext => {
var harvesterContext = new HarvestElementsContext {
Content = context.Content
@@ -55,7 +55,7 @@ namespace Orchard.Layouts.Services {
public IEnumerable<CategoryDescriptor> GetCategories(DescribeElementsContext context) {
var contentType = context.Content != null ? context.Content.ContentItem.ContentType : default(string);
return _cacheManager.Get(String.Format("ElementCategories-{0}", contentType ?? "AnyType"), acquireContext => {
return _cacheManager.Get(String.Format("ElementCategories-{0}-{1}", contentType ?? "AnyType", context.CacheVaryParam), acquireContext => {
var elements = DescribeElements(context);
var categoryDictionary = GetCategories();
var categoryDescriptorDictionary = new Dictionary<string, CategoryDescriptor>();