mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
New view engines cache implementation for tenant compatibility with themes
--HG-- branch : dev
This commit is contained in:
38
src/Orchard/Mvc/ViewEngines/ThemeViewLocationCache.cs
Normal file
38
src/Orchard/Mvc/ViewEngines/ThemeViewLocationCache.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using System.Web.Caching;
|
||||||
|
using System.Web;
|
||||||
|
using System.Web.Hosting;
|
||||||
|
|
||||||
|
namespace Orchard.Mvc.ViewEngines {
|
||||||
|
public class ThemeViewLocationCache : IViewLocationCache {
|
||||||
|
private readonly string _requestTheme;
|
||||||
|
|
||||||
|
public ThemeViewLocationCache(string requestTheme) {
|
||||||
|
_requestTheme = requestTheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string AlterKey(string key) {
|
||||||
|
return key + ":" + _requestTheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetViewLocation(HttpContextBase httpContext, string key) {
|
||||||
|
if (httpContext == null) {
|
||||||
|
throw new ArgumentNullException("httpContext");
|
||||||
|
}
|
||||||
|
|
||||||
|
return (string)httpContext.Cache[AlterKey(key)];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InsertViewLocation(HttpContextBase httpContext, string key, string virtualPath) {
|
||||||
|
if (httpContext == null) {
|
||||||
|
throw new ArgumentNullException("httpContext");
|
||||||
|
}
|
||||||
|
|
||||||
|
httpContext.Cache.Insert(AlterKey(key), virtualPath, new CacheDependency(HostingEnvironment.MapPath("~/Themes")), Cache.NoAbsoluteExpiration, TimeSpan);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,6 +31,8 @@ namespace Orchard.Mvc.ViewEngines {
|
|||||||
AreaPartialViewLocationFormats = DisabledFormats,
|
AreaPartialViewLocationFormats = DisabledFormats,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
viewEngine.ViewLocationCache = new ThemeViewLocationCache(parameters.VirtualPath);
|
||||||
|
|
||||||
// enable /Views/{partialName}
|
// enable /Views/{partialName}
|
||||||
// enable /Views/"DisplayTemplates/"+{templateName}
|
// enable /Views/"DisplayTemplates/"+{templateName}
|
||||||
// enable /Views/"EditorTemplates/+{templateName}
|
// enable /Views/"EditorTemplates/+{templateName}
|
||||||
|
|||||||
@@ -235,6 +235,7 @@
|
|||||||
<Compile Include="Mvc\Routes\UrlPrefix.cs" />
|
<Compile Include="Mvc\Routes\UrlPrefix.cs" />
|
||||||
<Compile Include="Mvc\Routes\UrlPrefixAdjustedHttpContext.cs" />
|
<Compile Include="Mvc\Routes\UrlPrefixAdjustedHttpContext.cs" />
|
||||||
<Compile Include="Mvc\Routes\ShellRoute.cs" />
|
<Compile Include="Mvc\Routes\ShellRoute.cs" />
|
||||||
|
<Compile Include="Mvc\ViewEngines\ThemeViewLocationCache.cs" />
|
||||||
<Compile Include="Mvc\ViewModels\AdaptedViewModel.cs" />
|
<Compile Include="Mvc\ViewModels\AdaptedViewModel.cs" />
|
||||||
<Compile Include="Mvc\ViewUserControl.cs">
|
<Compile Include="Mvc\ViewUserControl.cs">
|
||||||
<SubType>ASPXCodeBehind</SubType>
|
<SubType>ASPXCodeBehind</SubType>
|
||||||
|
|||||||
Reference in New Issue
Block a user