Creating the SysCache module in order to allow database caching

--HG--
branch : NH3
This commit is contained in:
Sebastien Ros
2012-07-13 14:55:47 -07:00
parent 5ed0af8243
commit b2e5973deb
11 changed files with 266 additions and 9 deletions

View File

@@ -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

View File

@@ -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")]

View File

@@ -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<NHibernate.Caches.SysCache2.SysCacheProvider>();
cache.UseQueryCache = true;
cache.RegionsPrefix = _shellSettings.Name;
}
}
}

View File

@@ -0,0 +1,125 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{3BD22132-D538-48C6-8854-F71333C798EB}</ProjectGuid>
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SysCache</RootNamespace>
<AssemblyName>SysCache</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<MvcBuildViews>false</MvcBuildViews>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>3.5</OldToolsVersion>
<UpgradeBackupLocation />
<TargetFrameworkProfile />
<UseIISExpress>false</UseIISExpress>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="NHibernate">
<HintPath>..\..\..\..\lib\nhibernate\NHibernate.dll</HintPath>
</Reference>
<Reference Include="NHibernate.Caches.SysCache2">
<HintPath>..\..\..\..\lib\nhibernate\NHibernate.Caches.SysCache2.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.ComponentModel.DataAnnotations">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Web.DynamicData" />
<Reference Include="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\lib\aspnetmvc\System.Web.Mvc.dll</HintPath>
</Reference>
<Reference Include="System.Web" />
<Reference Include="System.Web.Abstractions" />
<Reference Include="System.Web.Routing" />
<Reference Include="System.Xml" />
<Reference Include="System.Configuration" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Content Include="Web.config" />
<Content Include="Properties\AssemblyInfo.cs" />
<Content Include="Module.txt" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Orchard\Orchard.Framework.csproj">
<Project>{2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6}</Project>
<Name>Orchard.Framework</Name>
</ProjectReference>
<ProjectReference Include="..\..\Core\Orchard.Core.csproj">
<Project>{9916839C-39FC-4CEB-A5AF-89CA7E87119F}</Project>
<Name>Orchard.Core</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Compile Include="Services\SysCacheDatabaseCacheConfiguration.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target> -->
<Target Name="AfterBuild" DependsOnTargets="AfterBuildCompiler">
<PropertyGroup>
<AreasManifestDir>$(ProjectDir)\..\Manifests</AreasManifestDir>
</PropertyGroup>
<!-- If this is an area child project, uncomment the following line:
<CreateAreaManifest AreaName="$(AssemblyName)" AreaType="Child" AreaPath="$(ProjectDir)" ManifestPath="$(AreasManifestDir)" ContentFiles="@(Content)" />
-->
<!-- If this is an area parent project, uncomment the following lines:
<CreateAreaManifest AreaName="$(AssemblyName)" AreaType="Parent" AreaPath="$(ProjectDir)" ManifestPath="$(AreasManifestDir)" ContentFiles="@(Content)" />
<CopyAreaManifests ManifestPath="$(AreasManifestDir)" CrossCopy="false" RenameViews="true" />
-->
</Target>
<Target Name="AfterBuildCompiler" Condition="'$(MvcBuildViews)'=='true'">
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(ProjectDir)\..\$(ProjectName)" />
</Target>
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<UseIIS>False</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>45979</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>
</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>True</UseCustomServer>
<CustomServerUrl>http://orchard.codeplex.com</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
</Project>

View File

@@ -0,0 +1,41 @@
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<remove name="host" />
<remove name="pages" />
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<pages pageBaseType="Orchard.Mvc.ViewEngines.Razor.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
<add namespace="System.Linq"/>
<add namespace="System.Collections.Generic"/>
<add namespace="Orchard.Mvc.Html"/>
</namespaces>
</pages>
</system.web.webPages.razor>
<system.web>
<compilation targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</assemblies>
</compilation>
</system.web>
</configuration>

View File

@@ -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

View File

@@ -0,0 +1,9 @@
using NHibernate.Cfg.Loquacious;
namespace Orchard.Data {
public class DefaultDatabaseCacheConfiguration : IDatabaseCacheConfiguration {
public void Configure(ICacheConfigurationProperties cache) {
// do nothing, no cache
}
}
}

View File

@@ -0,0 +1,7 @@
using NHibernate.Cfg.Loquacious;
namespace Orchard.Data {
public interface IDatabaseCacheConfiguration : IDependency {
void Configure(ICacheConfigurationProperties cache);
}
}

View File

@@ -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<NHibernate.Caches.SysCache2.SysCacheProvider>();
c.UseQueryCache = true;
})
;
}
public static AutoPersistenceModel CreatePersistenceModel(ICollection<RecordBlueprint> recordDescriptors) {

View File

@@ -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.

View File

@@ -165,6 +165,8 @@
<Compile Include="ContentManagement\Utilities\ComputedField.cs" />
<Compile Include="Data\Conventions\AggregateAttribute.cs" />
<Compile Include="Data\Conventions\CacheConvention.cs" />
<Compile Include="Data\DefaultDatabaseCacheConfiguration.cs" />
<Compile Include="Data\IDatabaseCacheConfiguration.cs" />
<Compile Include="Data\Migration\AutomaticDataMigrations.cs" />
<Compile Include="DisplayManagement\Descriptors\PlacementInfo.cs" />
<Compile Include="DisplayManagement\Descriptors\ResourceBindingStrategy\StylesheetBindingStrategy.cs" />