/// <summary> /// Builds an array of strings which must be used as tags for the cache entry identifier of a specific cached content segment. /// </summary> /// <param name="configuration"></param> /// <param name="fusionPath"></param> /// <param name="fusionObject"></param> /// <returns></returns> protected string[] BuildCachetags(FusionObjectCacheConfiguration configuration, string fusionPath, AbstractFusionObject fusionObject) { var cacheTags = new List <string>(); if (configuration.EntryTags.Count > 0) { foreach (var kvp in configuration.EntryTags) { var tagValue = runtime.Evaluate(fusionPath + "/__meta/cache/entryTags/" + kvp.Key, fusionObject); if (tagValue is IEnumerable) { foreach (var item in (IEnumerable)tagValue) { cacheTags.Add((string)item); } } else if (tagValue is string) { cacheTags.Add((string)tagValue); } } cacheTags.AddRange(FlushTags()); } else { cacheTags.Add("Everything"); } return(cacheTags.Distinct().ToArray()); }
/// <summary> /// Enter an evaluation /// /// Needs to be called right before evaluation of a path start to check the cache mode and set /// internal state like the cache entry point. /// </summary> /// <param name="configuration"></param> /// <param name="fusionPath"></param> /// <returns></returns> public EvaluationContext Enter(FusionObjectCacheConfiguration configuration, string fusionPath) { var cacheForPathEnabled = configuration.Mode == FusionObjectCacheConfiguration.CacheMode.Cached || configuration.Mode == FusionObjectCacheConfiguration.CacheMode.Dynamic; var cacheForPathDisabled = configuration.Mode == FusionObjectCacheConfiguration.CacheMode.Uncached || configuration.Mode == FusionObjectCacheConfiguration.CacheMode.Dynamic; if (cacheForPathDisabled && configuration.Context.Count == 0) { throw new Exception($"Missing @cache.context configuration for path \"{fusionPath}\". An uncached segment must have one or more context variable names configured."); } var currentPathIsEntryPoint = false; if (EnableContentCache || cacheForPathEnabled) { if (!inCacheEntryPoint) { inCacheEntryPoint = true; currentPathIsEntryPoint = true; } } return(new EvaluationContext() { Configuration = configuration, FusionPath = fusionPath, CacheForPathEnabled = cacheForPathEnabled, CacheForPathDisabled = cacheForPathDisabled, CurrentPathIsEntryPoint = currentPathIsEntryPoint, }); }
/// <summary> /// Builds an array of additional key/values which must go into the calculation of the cache entry identifier /// for a cached content segment /// </summary> /// <param name="configuration"></param> /// <param name="fusionPath"></param> /// <param name="fusionObject"></param> /// <returns></returns> protected string[] BuildCacheIdentifierValues(FusionObjectCacheConfiguration configuration, string fusionPath, AbstractFusionObject fusionObject) { var objectType = "<Neos.Fusion:GlobalCacheIdentifiers>"; if (!string.IsNullOrEmpty(configuration.EntryIdentifier.ObjectType)) { objectType = $"<{configuration.EntryIdentifier.ObjectType}>"; } try { var entryIdentifiers = (System.Collections.IEnumerable)runtime.Evaluate(fusionPath + "/__meta/cache/entryIdentifier" + objectType, fusionObject); var result = new List <string>(); foreach (var entryIdentifier in entryIdentifiers) { result.Add((string)entryIdentifier); } return(result.ToArray()); } catch (Exception) { return(new string[] { }); } }