示例#1
0
        public override CacheDependency GetCacheDependency(string virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart)
        {
            var styleResult = ThemeHelper.IsStyleSheet(virtualPath);

            if (styleResult == null || styleResult.IsCss)
            {
                return(base.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart));
            }

            if (styleResult.IsThemeVars || styleResult.IsModuleImports)
            {
                return(null);
            }

            // Is Sass Or Less Or StyleBundle

            var arrPathDependencies = virtualPathDependencies.Cast <string>().ToArray();


            // Exclude the special imports from the file dependencies list,
            // 'cause this one cannot be monitored by the physical file system
            var fileDependencies = ThemeHelper.RemoveVirtualImports(arrPathDependencies);

            if (fileDependencies == arrPathDependencies)
            {
                // No themevars or moduleimports import... so no special considerations here
                return(base.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart));
            }

            if (fileDependencies.Any())
            {
                string cacheKey = null;

                var isThemeableAsset = (!styleResult.IsBundle && ThemeHelper.PathIsInheritableThemeFile(virtualPath)) ||
                                       (styleResult.IsBundle && fileDependencies.Any(x => ThemeHelper.PathIsInheritableThemeFile(x)));

                if (isThemeableAsset)
                {
                    var theme   = ThemeHelper.ResolveCurrentTheme();
                    int storeId = ThemeHelper.ResolveCurrentStoreId();
                    // invalidate the cache when variables change
                    cacheKey = FrameworkCacheConsumer.BuildThemeVarsCacheKey(theme.ThemeName, storeId);

                    if (styleResult.IsSass && (ThemeHelper.IsStyleValidationRequest()))
                    {
                        // Special case: ensure that cached validation result gets nuked in a while,
                        // when ThemeVariableService publishes the entity changed messages.
                        return(new CacheDependency(new string[0], new string[] { cacheKey }, utcStart));
                    }
                }

                return(new CacheDependency(
                           ThemingVirtualPathProvider.MapDependencyPaths(fileDependencies),
                           cacheKey == null ? new string[0] : new string[] { cacheKey },
                           utcStart));
            }

            return(null);
        }
        public override CacheDependency GetCacheDependency(
            string virtualPath,
            IEnumerable virtualPathDependencies,
            DateTime utcStart)
        {
            bool isLess;

            if (IsStyleSheet(virtualPath, out isLess))
            {
                if (isLess)
                {
                    // the LESS HTTP handler made the call
                    // [...]
                }
                else
                {
                    // the Bundler made the call
                    var bundle = BundleTable.Bundles.GetBundleFor(virtualPath);
                    if (bundle == null)
                    {
                        return(_previous.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart));
                    }
                }

                var arrPathDependencies = virtualPathDependencies.Cast <string>().ToArray();

                // determine the virtual themevars.less import reference
                var themeVarsFile = arrPathDependencies.Where(x => ThemeHelper.PathIsThemeVars(x)).FirstOrDefault();

                if (themeVarsFile.IsEmpty())
                {
                    // no themevars import... so no special considerations here
                    return(_previous.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart));
                }

                // exclude the themevars import from the file dependencies list,
                // 'cause this one cannot be monitored by the physical file system
                var fileDependencies = arrPathDependencies.Except(new string[] { themeVarsFile });

                if (arrPathDependencies.Any())
                {
                    int    storeId   = ResolveCurrentStoreId();
                    string themeName = ResolveCurrentThemeName();
                    // invalidate the cache when variables change
                    string cacheKey        = AspNetCache.BuildKey(FrameworkCacheConsumer.BuildThemeVarsCacheKey(themeName, storeId));
                    var    cacheDependency = new CacheDependency(fileDependencies.Select(x => HostingEnvironment.MapPath(x)).ToArray(), new string[] { cacheKey }, utcStart);
                    return(cacheDependency);
                }

                return(null);
            }

            return(_previous.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart));
        }
示例#3
0
        internal virtual ExpandoObject GetRawVariables(string themeName, int storeId)
        {
            // we need the Asp.Net cache here in order to define cacheKey dependencies

            string cacheKey = FrameworkCacheConsumer.BuildThemeVarsCacheKey(themeName, storeId);

            return(HttpRuntime.Cache.GetOrAdd(cacheKey, () =>
            {
                var themeVarService = EngineContext.Current.Resolve <IThemeVariablesService>();
                return themeVarService.GetThemeVariables(themeName, storeId) ?? new ExpandoObject();
            }));
        }
        public string GetVariablesAsLess(string themeName, int storeId)
        {
            Guard.ArgumentNotEmpty(() => themeName);
            Guard.ArgumentIsPositive(storeId, "storeId");

            // we need the Asp.Net here cache in order to define cacheKey dependencies
            var cacheManager = EngineContext.Current.ContainerManager.Resolve <ICacheManager>("aspnet");

            string cacheKey = FrameworkCacheConsumer.BuildThemeVarsCacheKey(themeName, storeId);

            return(cacheManager.Get(cacheKey, () =>
            {
                var variables = GetLessCssVariables(themeName, storeId);
                var lessCss = TransformToLess(variables);
                return lessCss;
            }));
        }
        public override CacheDependency GetCacheDependency(string virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart)
        {
            bool isLess;
            bool isBundle;

            if (!ThemeHelper.IsStyleSheet(virtualPath, out isLess, out isBundle))
            {
                return(GetCacheDependencyInternal(virtualPath, virtualPathDependencies, utcStart));
            }
            else
            {
                if (!isLess && !isBundle)
                {
                    // it's a static css file (no bundle, no less)
                    return(GetCacheDependencyInternal(virtualPath, virtualPathDependencies, utcStart));
                }

                var arrPathDependencies = virtualPathDependencies.Cast <string>().ToArray();

                // determine the virtual themevars.less import reference
                var themeVarsFile = arrPathDependencies.Where(x => ThemeHelper.PathIsThemeVars(x)).FirstOrDefault();

                if (themeVarsFile.IsEmpty())
                {
                    // no themevars import... so no special considerations here
                    return(GetCacheDependencyInternal(virtualPath, virtualPathDependencies, utcStart));
                }

                // exclude the themevars import from the file dependencies list,
                // 'cause this one cannot be monitored by the physical file system
                var fileDependencies = arrPathDependencies.Except(new string[] { themeVarsFile });

                if (arrPathDependencies.Any())
                {
                    int storeId = ThemeHelper.ResolveCurrentStoreId();
                    var theme   = ThemeHelper.ResolveCurrentTheme();
                    // invalidate the cache when variables change
                    string cacheKey        = AspNetCache.BuildKey(FrameworkCacheConsumer.BuildThemeVarsCacheKey(theme.ThemeName, storeId));
                    var    cacheDependency = new CacheDependency(MapDependencyPaths(fileDependencies), new string[] { cacheKey }, utcStart);
                    return(cacheDependency);
                }

                return(null);
            }
        }
示例#6
0
        internal virtual ExpandoObject GetRawVariables(string themeName, int storeId)
        {
            // we need the Asp.Net cache here in order to define cacheKey dependencies
            bool validationMode = ThemeHelper.IsStyleValidationRequest();

            if (validationMode)
            {
                // Return uncached fresh data (the variables is not nuked yet)
                return(GetRawVariablesCore(themeName, storeId));
            }
            else
            {
                string cacheKey = FrameworkCacheConsumer.BuildThemeVarsCacheKey(themeName, storeId);
                return(HttpRuntime.Cache.GetOrAdd(cacheKey, () =>
                {
                    return GetRawVariablesCore(themeName, storeId);
                }));
            }
        }
        internal virtual ExpandoObject GetRawVariables(string themeName, int storeId)
        {
            // we need the Asp.Net here cache in order to define cacheKey dependencies
            var cacheManager = EngineContext.Current.ContainerManager.Resolve <ICacheManager>("aspnet");

            string cacheKey = FrameworkCacheConsumer.BuildThemeVarsCacheKey(themeName, storeId);

            return(cacheManager.Get(cacheKey, () =>
            {
                var themeVarService = EngineContext.Current.Resolve <IThemeVariablesService>();
                var result = themeVarService.GetThemeVariables(themeName, storeId);

                if (result == null)
                {
                    return new ExpandoObject();
                }

                return result;
            }));
        }
示例#8
0
        /// <summary>
        /// Invalidates a cached asset when any themevar was changed or the theme was touched on file system
        /// </summary>
        /// <param name="entry"></param>
        private static void SetupEvictionObserver(CachedAssetEntry entry)
        {
            if (entry.ThemeName == null)
            {
                return;
            }

            var cacheKey = CacheKeyPrefix + "{0}:{1}".FormatInvariant(entry.ThemeName, entry.StoreId);

            var cacheDependency = new CacheDependency(
                new string[0],
                new[] { FrameworkCacheConsumer.BuildThemeVarsCacheKey(entry.ThemeName, entry.StoreId) },
                DateTime.UtcNow);

            HttpRuntime.Cache.Insert(
                cacheKey,
                entry.PhysicalPath,
                cacheDependency,
                Cache.NoAbsoluteExpiration,
                Cache.NoSlidingExpiration,
                CacheItemPriority.Default,
                OnCacheItemRemoved);
        }
 public void AddFileDependencies(ICollection <string> mappedPaths, ICollection <string> cacheKeys)
 {
     cacheKeys.Add(FrameworkCacheConsumer.BuildThemeVarsCacheKey(ThemeName, StoreId));
 }