public override CacheDependency GetCacheDependency(string virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart) { var styleResult = ThemeHelper.IsStyleSheet(virtualPath); if (styleResult == null) { return(GetCacheDependencyInternal(virtualPath, virtualPathDependencies, utcStart)); } else { if (styleResult.IsCss) { // it's a static css file (no bundle, no sass/less) return(GetCacheDependencyInternal(virtualPath, virtualPathDependencies, utcStart)); } var arrPathDependencies = virtualPathDependencies.Cast <string>().ToArray(); // determine the virtual themevars.(scss|less) import reference var themeVarsFile = arrPathDependencies.Where(x => ThemeHelper.PathIsThemeVars(x)).FirstOrDefault(); var moduleImportsFile = arrPathDependencies.Where(x => ThemeHelper.PathIsModuleImports(x)).FirstOrDefault(); if (themeVarsFile.IsEmpty() && moduleImportsFile.IsEmpty()) { // no themevars or moduleimports import... so no special considerations here return(GetCacheDependencyInternal(virtualPath, virtualPathDependencies, utcStart)); } // exclude the special imports from the file dependencies list, // 'cause this one cannot be monitored by the physical file system var fileDependencies = arrPathDependencies.Except((new string[] { themeVarsFile, moduleImportsFile }).Where(x => x.HasValue())); if (arrPathDependencies.Any()) { int storeId = ThemeHelper.ResolveCurrentStoreId(); var theme = ThemeHelper.ResolveCurrentTheme(); // invalidate the cache when variables change string cacheKey = FrameworkCacheConsumer.BuildThemeVarsCacheKey(theme.ThemeName, storeId); var cacheDependency = new CacheDependency(MapDependencyPaths(fileDependencies), new string[] { cacheKey }, utcStart); return(cacheDependency); } return(null); } }
internal static IEnumerable <string> RemoveVirtualImports(IEnumerable <string> virtualPathDependencies) { Guard.NotNull(virtualPathDependencies, nameof(virtualPathDependencies)); // determine the virtual themevars scss import reference var themeVarsFile = virtualPathDependencies.Where(x => ThemeHelper.PathIsThemeVars(x)).FirstOrDefault(); var moduleImportsFile = virtualPathDependencies.Where(x => ThemeHelper.PathIsModuleImports(x)).FirstOrDefault(); if (themeVarsFile == null && moduleImportsFile == null) { // no themevars or moduleimports import... so no special considerations here return(virtualPathDependencies); } // exclude the special imports from the file dependencies list, // 'cause this one cannot be monitored by the physical file system return(virtualPathDependencies .Except((new string[] { themeVarsFile, moduleImportsFile }) .Where(x => x.HasValue())) .ToArray()); }