public string GetCacheKey(int contentItemId, string displayType, ItemLevelCacheSettings cacheSettings)
        {
            if (cacheSettings == null)
            {
                return(null);
            }

            var enabledCacheKeys = cacheSettings.CompositeCacheKeyProviders.Where(kvp => kvp.Value).Select(kvp => kvp.Key);

            var compositeCacheKeys =
                mCompositeCacheKeyProviders
                .Where(p => enabledCacheKeys.Contains(p.TechnicalName))
                .OrderBy(p => p.TechnicalName)
                .Select(p => $"{p.TechnicalName}={p.GetCacheKeyValue()}");

            return($"ItemLevelCache; {contentItemId}; {displayType}; {String.Join("; ", compositeCacheKeys)}");
        }
Example #2
0
        protected override void Importing(ItemLevelCachePart part, ImportContentContext context)
        {
            var element = context.Data.Element(part.PartDefinition.Name);

            // Don't do anything if the tag is not specified.
            if (context.Data.Element(part.PartDefinition.Name) == null)
            {
                return;
            }

            var dictionary = new Dictionary <string, ItemLevelCacheSettings>();

            foreach (var displayTypeElement in element.Elements())
            {
                var settings = new ItemLevelCacheSettings
                {
                    InheritDefaultSettings = false,
                    Mode = (ItemLevelCacheMode)Enum.Parse(typeof(ItemLevelCacheMode), displayTypeElement.Attribute("Mode").Value),
                    InvalidationAction    = (ItemLevelCacheInvalidationAction)Enum.Parse(typeof(ItemLevelCacheInvalidationAction), displayTypeElement.Attribute("InvalidationAction").Value),
                    CacheDurationSeconds  = (int)displayTypeElement.Attribute("CacheDurationSeconds"),
                    CacheGraceTimeSeconds = (int)displayTypeElement.Attribute("CacheGraceTimeSeconds")
                };

                var compositeCacheKeysElement = displayTypeElement.Element("CompositeCacheKeys");

                if (compositeCacheKeysElement != null)
                {
                    foreach (var compositeCacheKeyElement in compositeCacheKeysElement.Elements())
                    {
                        settings.CompositeCacheKeyProviders[compositeCacheKeyElement.Name.LocalName] = (bool)compositeCacheKeyElement.Attribute("Enabled");
                    }
                }

                dictionary[displayTypeElement.Name.LocalName] = settings;
            }

            part.ItemLevelCacheSettings           = dictionary;
            part.SerializedItemLevelCacheSettings = mJsonConverter.Serialize(part.ItemLevelCacheSettings);
        }