From b2e5973debe0cab68dd2f6b6ae21933c30e8e974 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Fri, 13 Jul 2012 14:55:47 -0700 Subject: [PATCH] Creating the SysCache module in order to allow database caching --HG-- branch : NH3 --- src/Orchard.Web/Modules/SysCache/Module.txt | 11 ++ .../SysCache/Properties/AssemblyInfo.cs | 36 +++++ .../SysCacheDatabaseCacheConfiguration.cs | 21 +++ .../Modules/SysCache/SysCache.csproj | 125 ++++++++++++++++++ src/Orchard.Web/Modules/SysCache/Web.config | 41 ++++++ src/Orchard.sln | 7 + .../Data/DefaultDatabaseCacheConfiguration.cs | 9 ++ .../Data/IDatabaseCacheConfiguration.cs | 7 + .../Providers/AbstractDataServicesProvider.cs | 5 - src/Orchard/Data/SessionFactoryHolder.cs | 11 +- src/Orchard/Orchard.Framework.csproj | 2 + 11 files changed, 266 insertions(+), 9 deletions(-) create mode 100644 src/Orchard.Web/Modules/SysCache/Module.txt create mode 100644 src/Orchard.Web/Modules/SysCache/Properties/AssemblyInfo.cs create mode 100644 src/Orchard.Web/Modules/SysCache/Services/SysCacheDatabaseCacheConfiguration.cs create mode 100644 src/Orchard.Web/Modules/SysCache/SysCache.csproj create mode 100644 src/Orchard.Web/Modules/SysCache/Web.config create mode 100644 src/Orchard/Data/DefaultDatabaseCacheConfiguration.cs create mode 100644 src/Orchard/Data/IDatabaseCacheConfiguration.cs diff --git a/src/Orchard.Web/Modules/SysCache/Module.txt b/src/Orchard.Web/Modules/SysCache/Module.txt new file mode 100644 index 000000000..656daa6eb --- /dev/null +++ b/src/Orchard.Web/Modules/SysCache/Module.txt @@ -0,0 +1,11 @@ +Name: SysCache +AntiForgery: enabled +Author: The Orchard Team +Website: http://orchardproject.net +Version: 1.6 +OrchardVersion: 1.6 +Description: Enables database caching using the SysCache provider. +Features: + SysCache: + Description: Enables database caching using the SysCache provider. + Category: Performance \ No newline at end of file diff --git a/src/Orchard.Web/Modules/SysCache/Properties/AssemblyInfo.cs b/src/Orchard.Web/Modules/SysCache/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..6d26deda9 --- /dev/null +++ b/src/Orchard.Web/Modules/SysCache/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("SysCache")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyProduct("Orchard")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("4b8511d8-1095-4d6e-9eae-663e62929f68")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] + diff --git a/src/Orchard.Web/Modules/SysCache/Services/SysCacheDatabaseCacheConfiguration.cs b/src/Orchard.Web/Modules/SysCache/Services/SysCacheDatabaseCacheConfiguration.cs new file mode 100644 index 000000000..4c3da595b --- /dev/null +++ b/src/Orchard.Web/Modules/SysCache/Services/SysCacheDatabaseCacheConfiguration.cs @@ -0,0 +1,21 @@ +using NHibernate.Cfg.Loquacious; +using Orchard.Data; +using Orchard.Environment.Configuration; +using Orchard.Environment.Extensions; + +namespace SysCache.Services { + [OrchardSuppressDependency("Orchard.Data.DefaultDatabaseCacheConfiguration")] + public class SysCacheDatabaseCacheConfiguration : IDatabaseCacheConfiguration { + private readonly ShellSettings _shellSettings; + + public SysCacheDatabaseCacheConfiguration(ShellSettings shellSettings) { + _shellSettings = shellSettings; + } + + public void Configure(ICacheConfigurationProperties cache) { + cache.Provider(); + cache.UseQueryCache = true; + cache.RegionsPrefix = _shellSettings.Name; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/SysCache/SysCache.csproj b/src/Orchard.Web/Modules/SysCache/SysCache.csproj new file mode 100644 index 000000000..cd934fc1c --- /dev/null +++ b/src/Orchard.Web/Modules/SysCache/SysCache.csproj @@ -0,0 +1,125 @@ + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {3BD22132-D538-48C6-8854-F71333C798EB} + {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + SysCache + SysCache + v4.0 + false + + + 3.5 + + + false + + + true + full + false + bin\ + DEBUG;TRACE + prompt + 4 + AllRules.ruleset + + + pdbonly + true + bin\ + TRACE + prompt + 4 + AllRules.ruleset + + + + + ..\..\..\..\lib\nhibernate\NHibernate.dll + + + ..\..\..\..\lib\nhibernate\NHibernate.Caches.SysCache2.dll + + + + + 3.5 + + + + False + ..\..\..\..\lib\aspnetmvc\System.Web.Mvc.dll + + + + + + + + + + + + + + + + {2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6} + Orchard.Framework + + + {9916839C-39FC-4CEB-A5AF-89CA7E87119F} + Orchard.Core + + + + + + + + + + + + $(ProjectDir)\..\Manifests + + + + + + + + + + + + False + True + 45979 + / + + + False + True + http://orchard.codeplex.com + False + + + + + \ No newline at end of file diff --git a/src/Orchard.Web/Modules/SysCache/Web.config b/src/Orchard.Web/Modules/SysCache/Web.config new file mode 100644 index 000000000..88b84a792 --- /dev/null +++ b/src/Orchard.Web/Modules/SysCache/Web.config @@ -0,0 +1,41 @@ + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Orchard.sln b/src/Orchard.sln index bbbc4ab7a..69f0987e6 100644 --- a/src/Orchard.sln +++ b/src/Orchard.sln @@ -148,6 +148,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orchard.ContentPicker", "Or EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orchard.ContentPermissions", "Orchard.Web\Modules\Orchard.ContentPermissions\Orchard.ContentPermissions.csproj", "{E826F796-8CE3-4B5B-8423-5AA5F81D2FC3}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SysCache", "Orchard.Web\Modules\SysCache\SysCache.csproj", "{3BD22132-D538-48C6-8854-F71333C798EB}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution CodeCoverage|Any CPU = CodeCoverage|Any CPU @@ -157,6 +159,10 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3BD22132-D538-48C6-8854-F71333C798EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3BD22132-D538-48C6-8854-F71333C798EB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3BD22132-D538-48C6-8854-F71333C798EB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3BD22132-D538-48C6-8854-F71333C798EB}.Release|Any CPU.Build.0 = Release|Any CPU {50B779EA-EC00-4699-84C0-03B395C365D2}.CodeCoverage|Any CPU.ActiveCfg = Release|Any CPU {50B779EA-EC00-4699-84C0-03B395C365D2}.CodeCoverage|Any CPU.Build.0 = Release|Any CPU {50B779EA-EC00-4699-84C0-03B395C365D2}.Coverage|Any CPU.ActiveCfg = Release|Any CPU @@ -872,5 +878,6 @@ Global {34BE9011-A5A9-49DD-9E53-C3D5CA7D7CE3} = {3E10BF6D-ADA5-417D-B36C-EBB0660B475E} {AC4402A1-61C4-4229-B840-FB1777DAE10C} = {3E10BF6D-ADA5-417D-B36C-EBB0660B475E} {CB70A642-8CEC-4DDE-8C9F-AD08900EC98D} = {74492CBC-7201-417E-BC29-28B4C25A58B0} + {3BD22132-D538-48C6-8854-F71333C798EB} = {E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5} EndGlobalSection EndGlobal diff --git a/src/Orchard/Data/DefaultDatabaseCacheConfiguration.cs b/src/Orchard/Data/DefaultDatabaseCacheConfiguration.cs new file mode 100644 index 000000000..9debb87a4 --- /dev/null +++ b/src/Orchard/Data/DefaultDatabaseCacheConfiguration.cs @@ -0,0 +1,9 @@ +using NHibernate.Cfg.Loquacious; + +namespace Orchard.Data { + public class DefaultDatabaseCacheConfiguration : IDatabaseCacheConfiguration { + public void Configure(ICacheConfigurationProperties cache) { + // do nothing, no cache + } + } +} \ No newline at end of file diff --git a/src/Orchard/Data/IDatabaseCacheConfiguration.cs b/src/Orchard/Data/IDatabaseCacheConfiguration.cs new file mode 100644 index 000000000..65e7f85d8 --- /dev/null +++ b/src/Orchard/Data/IDatabaseCacheConfiguration.cs @@ -0,0 +1,7 @@ +using NHibernate.Cfg.Loquacious; + +namespace Orchard.Data { + public interface IDatabaseCacheConfiguration : IDependency { + void Configure(ICacheConfigurationProperties cache); + } +} \ No newline at end of file diff --git a/src/Orchard/Data/Providers/AbstractDataServicesProvider.cs b/src/Orchard/Data/Providers/AbstractDataServicesProvider.cs index c54bba2e3..6bf72b849 100644 --- a/src/Orchard/Data/Providers/AbstractDataServicesProvider.cs +++ b/src/Orchard/Data/Providers/AbstractDataServicesProvider.cs @@ -32,12 +32,7 @@ namespace Orchard.Data.Providers { .Mappings(m => m.AutoMappings.Add(persistenceModel)) .ExposeConfiguration(cfg => cfg.EventListeners.LoadEventListeners = new ILoadEventListener[] { new OrchardLoadEventListener() }) .BuildConfiguration() - .Cache(c => { - c.Provider(); - c.UseQueryCache = true; - }) ; - } public static AutoPersistenceModel CreatePersistenceModel(ICollection recordDescriptors) { diff --git a/src/Orchard/Data/SessionFactoryHolder.cs b/src/Orchard/Data/SessionFactoryHolder.cs index eb933e7a7..00226f598 100644 --- a/src/Orchard/Data/SessionFactoryHolder.cs +++ b/src/Orchard/Data/SessionFactoryHolder.cs @@ -21,6 +21,7 @@ namespace Orchard.Data { private readonly ShellSettings _shellSettings; private readonly ShellBlueprint _shellBlueprint; private readonly IHostEnvironment _hostEnvironment; + private readonly IDatabaseCacheConfiguration _cacheConfiguration; private readonly IDataServicesProviderFactory _dataServicesProviderFactory; private readonly IAppDataFolder _appDataFolder; private readonly ISessionConfigurationCache _sessionConfigurationCache; @@ -34,13 +35,15 @@ namespace Orchard.Data { IDataServicesProviderFactory dataServicesProviderFactory, IAppDataFolder appDataFolder, ISessionConfigurationCache sessionConfigurationCache, - IHostEnvironment hostEnvironment) { + IHostEnvironment hostEnvironment, + IDatabaseCacheConfiguration cacheConfiguration) { _shellSettings = shellSettings; _shellBlueprint = shellBlueprint; _dataServicesProviderFactory = dataServicesProviderFactory; _appDataFolder = appDataFolder; _sessionConfigurationCache = sessionConfigurationCache; _hostEnvironment = hostEnvironment; + _cacheConfiguration = cacheConfiguration; T = NullLocalizer.Instance; Logger = NullLogger.Instance; @@ -94,10 +97,10 @@ namespace Orchard.Data { _dataServicesProviderFactory .CreateProvider(parameters) .BuildConfiguration(parameters) - .Cache( c => c.RegionsPrefix = _shellSettings.Name) - ); + .Cache(c => _cacheConfiguration.Configure(c)) + ); - #region NH-2.1.2 specific optimization + #region NH specific optimization // cannot be done in fluent config // the IsSelectable = false prevents unused ContentPartRecord proxies from being created // for each ContentItemRecord or ContentItemVersionRecord. diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj index fc4d50db1..d90983582 100644 --- a/src/Orchard/Orchard.Framework.csproj +++ b/src/Orchard/Orchard.Framework.csproj @@ -165,6 +165,8 @@ + +