New view engines cache implementation for tenant compatibility with themes

--HG--
branch : dev
This commit is contained in:
Sebastien Ros
2010-05-19 11:33:43 -07:00
parent 559a94af73
commit 19396e4f0c
3 changed files with 41 additions and 0 deletions

View 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);
}
}
}

View File

@@ -31,6 +31,8 @@ namespace Orchard.Mvc.ViewEngines {
AreaPartialViewLocationFormats = DisabledFormats,
};
viewEngine.ViewLocationCache = new ThemeViewLocationCache(parameters.VirtualPath);
// enable /Views/{partialName}
// enable /Views/"DisplayTemplates/"+{templateName}
// enable /Views/"EditorTemplates/+{templateName}

View File

@@ -235,6 +235,7 @@
<Compile Include="Mvc\Routes\UrlPrefix.cs" />
<Compile Include="Mvc\Routes\UrlPrefixAdjustedHttpContext.cs" />
<Compile Include="Mvc\Routes\ShellRoute.cs" />
<Compile Include="Mvc\ViewEngines\ThemeViewLocationCache.cs" />
<Compile Include="Mvc\ViewModels\AdaptedViewModel.cs" />
<Compile Include="Mvc\ViewUserControl.cs">
<SubType>ASPXCodeBehind</SubType>