Shifting CacheSettingsPart

This commit is contained in:
Sebastien Ros
2013-10-31 14:49:44 -07:00
parent ee878699cf
commit 07c41a05b6
6 changed files with 30 additions and 52 deletions

View File

@@ -3,7 +3,6 @@ using Orchard.OutputCache.Models;
using Orchard.OutputCache.Services;
using Orchard.ContentManagement;
using Orchard.Core.Common.Models;
using Orchard.Data;
using Orchard.ContentManagement.Handlers;
namespace Orchard.OutputCache.Handlers {
@@ -11,11 +10,9 @@ namespace Orchard.OutputCache.Handlers {
private readonly ICacheService _cacheService;
public CacheSettingsPartHandler(
IRepository<CacheSettingsPartRecord> repository,
ICacheService cacheService) {
_cacheService = cacheService;
Filters.Add(new ActivatingFilter<CacheSettingsPart>("Site"));
Filters.Add(StorageFilter.For(repository));
// initializing default cache settings values
OnInitializing<CacheSettingsPart>((context, part) => { part.DefaultCacheDuration = 300; });

View File

@@ -3,19 +3,7 @@
namespace Orchard.OutputCache {
public class Migrations : DataMigrationImpl {
public int Create() {
SchemaBuilder.CreateTable("CacheSettingsPartRecord",
table => table
.ContentPartRecord()
.Column<int>("DefaultCacheDuration")
.Column<int>("DefaultMaxAge")
.Column<string>("IgnoredUrls", c => c.Unlimited())
.Column<string>("VaryQueryStringParameters", c => c.Unlimited())
.Column<string>("VaryRequestHeaders", c => c.Unlimited())
.Column<bool>("DebugMode", c => c.WithDefault(false))
.Column<bool>("ApplyCulture", c => c.WithDefault(false))
);
SchemaBuilder.CreateTable("CacheParameterRecord",
table => table
.Column<int>("Id", c => c.PrimaryKey().Identity())

View File

@@ -1,42 +1,42 @@
using Orchard.ContentManagement;
namespace Orchard.OutputCache.Models {
public class CacheSettingsPart : ContentPart<CacheSettingsPartRecord> {
public class CacheSettingsPart : ContentPart {
public const string CacheKey = "CacheSettingsPart";
public int DefaultCacheDuration {
get { return Record.DefaultCacheDuration; }
set { Record.DefaultCacheDuration = value; }
get { return this.Retrieve(x => x.DefaultCacheDuration); }
set { this.Store(x => x.DefaultCacheDuration, value); }
}
public int DefaultMaxAge {
get { return Record.DefaultMaxAge; }
set { Record.DefaultMaxAge = value; }
get { return this.Retrieve(x => x.DefaultMaxAge); }
set { this.Store(x => x.DefaultMaxAge, value); }
}
public string VaryQueryStringParameters {
get { return Record.VaryQueryStringParameters; }
set { Record.VaryQueryStringParameters = value; }
get { return this.Retrieve(x => x.VaryQueryStringParameters); }
set { this.Store(x => x.VaryQueryStringParameters, value); }
}
public string VaryRequestHeaders {
get { return Record.VaryRequestHeaders; }
set { Record.VaryRequestHeaders = value; }
get { return this.Retrieve(x => x.VaryRequestHeaders); }
set { this.Store(x => x.VaryRequestHeaders, value); }
}
public string IgnoredUrls {
get { return Record.IgnoredUrls; }
set { Record.IgnoredUrls = value; }
get { return this.Retrieve(x => x.IgnoredUrls); }
set { this.Store(x => x.IgnoredUrls, value); }
}
public bool ApplyCulture {
get { return Record.ApplyCulture; }
set { Record.ApplyCulture = value; }
get { return this.Retrieve(x => x.ApplyCulture); }
set { this.Store(x => x.ApplyCulture, value); }
}
public bool DebugMode {
get { return Record.DebugMode; }
set { Record.DebugMode = value; }
get { return this.Retrieve(x => x.DebugMode); }
set { this.Store(x => x.DebugMode, value); }
}
}
}

View File

@@ -1,20 +0,0 @@
using Orchard.ContentManagement.Records;
using Orchard.Data.Conventions;
namespace Orchard.OutputCache.Models {
public class CacheSettingsPartRecord : ContentPartRecord {
public virtual int DefaultCacheDuration { get; set; }
public virtual int DefaultMaxAge { get; set; }
public virtual bool DebugMode { get; set; }
public virtual bool ApplyCulture { get; set; }
[StringLengthMax]
public virtual string VaryQueryStringParameters { get; set; }
[StringLengthMax]
public virtual string VaryRequestHeaders { get; set; }
[StringLengthMax]
public virtual string IgnoredUrls { get; set; }
}
}

View File

@@ -102,7 +102,6 @@
<Compile Include="Migrations.cs" />
<Compile Include="Models\CacheItem.cs" />
<Compile Include="Models\CacheSettingsPart.cs" />
<Compile Include="Models\CacheSettingsPartRecord.cs" />
<Compile Include="Models\CacheParameterRecord.cs" />
<Compile Include="Services\CacheService.cs" />
<Compile Include="Services\DefaultCacheControlStrategy.cs" />

View File

@@ -106,6 +106,20 @@ namespace Upgrade.Controllers {
_upgradeService.ExecuteReader("DROP TABLE " + _upgradeService.GetPrefixedTableName("Orchard_AntiSpam_TypePadSettingsPartRecord"), null);
// CacheSettingsPartRecord
_upgradeService.ExecuteReader("SELECT * FROM " + _upgradeService.GetPrefixedTableName("Orchard_OutputCache_CacheSettingsPartRecord"),
(reader, connection) => {
site.As<InfosetPart>().Store("CacheSettingsPart", "DefaultCacheDuration", (int)reader["DefaultCacheDuration"]);
site.As<InfosetPart>().Store("CacheSettingsPart", "DefaultMaxAge", (int)reader["DefaultMaxAge"]);
site.As<InfosetPart>().Store("CacheSettingsPart", "VaryQueryStringParameters", (string)reader["VaryQueryStringParameters"]);
site.As<InfosetPart>().Store("CacheSettingsPart", "VaryRequestHeaders", (string)reader["VaryRequestHeaders"]);
site.As<InfosetPart>().Store("CacheSettingsPart", "IgnoredUrls", (string)reader["IgnoredUrls"]);
site.As<InfosetPart>().Store("CacheSettingsPart", "ApplyCulture", (bool)reader["ApplyCulture"]);
site.As<InfosetPart>().Store("CacheSettingsPart", "DebugMode", (bool)reader["DebugMode"]);
});
_upgradeService.ExecuteReader("DROP TABLE " + _upgradeService.GetPrefixedTableName("Orchard_OutputCache_CacheSettingsPartRecord"), null);
_orchardServices.Notifier.Information(T("Site Settings migrated successfully"));