Permalink
Browse files

Merge branch 'feature/redis-cache-provider' into develop

  • Loading branch information...
picce committed Dec 27, 2017
2 parents c9eff69 + 37cb462 commit 6834056ec5b4dffb0263b492fb694c0a65d989d9
@@ -459,6 +459,9 @@ public FileMetaInfo DefaultImage
int counter = 0;
foreach (FileMetaInfo img in this.Images)
{
if (img.IsFolder)
continue;
if (counter == 0)
firstImg = img;
if (string.IsNullOrEmpty(defaultImageName))
@@ -185,6 +185,34 @@ public static string CultureDev
get { return getConfigValue("CultureDev", CultureDefault); }
}
/// <summary>
/// redis server connection string
/// </summary>
public static string RedisConnection
{
get { return getConfigValue("RedisConnection"); }
}
/// <summary>
/// redis app name, used to avoid same keys on redis server for different website instances
/// </summary>
public static string RedisAppName
{
get { return getConfigValue("RedisAppName", "Acme.PgnCore"); }
}
public static int RedisDefaultExpireSeconds
{
get
{
int res = 0;
string val = GetConfigValue("RedisDefaultExpireSeconds", "600");
int.TryParse(val, out res);
return res;
}
}
/// <summary>
/// used by fckeditr js plugin
/// </summary>
@@ -0,0 +1,107 @@
/***************************************************
PigeonCms - Open source Content Management System
https://github.com/picce/pigeoncms
Copyright © 2017 Nicola Ridolfi - picce@yahoo.it
Licensed under the terms of "GNU General Public License v3"
For the full license text see license.txt or
visit "http://www.gnu.org/licenses/gpl.html"
***************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Caching;
using System.Diagnostics;
using System.Collections;
using StackExchange.Redis;
using System.Configuration;
namespace PigeonCms.Core.Helpers
{
public class RedisStore
{
private static readonly Lazy<ConnectionMultiplexer> lazyConnection;
static RedisStore()
{
string redisConnection = Config.RedisConnection;
//var configurationOptions = new ConfigurationOptions
//{
// EndPoints = { redisConnection }
//};
//lazyConnection = new Lazy<ConnectionMultiplexer>(() => ConnectionMultiplexer.Connect(configurationOptions));
lazyConnection = new Lazy<ConnectionMultiplexer>(() => ConnectionMultiplexer.Connect(redisConnection));
}
public static ConnectionMultiplexer Connection => lazyConnection.Value;
public static IDatabase RedisCache => Connection.GetDatabase();
}
public class RedisProvider
{
private string appName = null;
public string AppName
{
get
{
if (appName == null)
{
appName = Config.RedisAppName;
}
return appName;
}
}
public TimeSpan DefaultExpire { get; set; }
public string KeyPrefix { get; }
public RedisProvider(string keyPrefix, TimeSpan? defaultExpire = null)
{
this.KeyPrefix = keyPrefix;
if (defaultExpire.HasValue)
this.DefaultExpire = defaultExpire.Value;
else
this.DefaultExpire = new TimeSpan(0, 0, Config.RedisDefaultExpireSeconds);
}
/// <summary>
/// generate complex key with format: AppName.KeyPrefix:key[field]#id
/// </summary>
/// <param name="key"></param>
/// <param name="field"></param>
/// <param name="id"></param>
/// <returns></returns>
public RedisKey K(string key, string field = "", string id = "")
{
string res = $"{this.AppName}.{this.KeyPrefix}:{key}";
if (!string.IsNullOrEmpty(field))
res += $"[{field}]";
if (!string.IsNullOrEmpty(id))
res += $"#{id}";
return res;
}
public TimeSpan Exp(TimeSpan? t = null)
{
TimeSpan res = this.DefaultExpire;
if (t.HasValue)
res = t.Value;
return res;
}
}
}
@@ -45,10 +45,19 @@
<HintPath>..\packages\ImageResizer.4.0.5\lib\net45\ImageResizer.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.Web.RedisOutputCacheProvider, Version=1.7.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.RedisOutputCacheProvider.1.7.5\lib\net40\Microsoft.Web.RedisOutputCacheProvider.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\pigeoncms\Bin\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="StackExchange.Redis.StrongName, Version=1.2.1.0, Culture=neutral, PublicKeyToken=c219ff1ca8c2ce46, processorArchitecture=MSIL">
<HintPath>..\packages\StackExchange.Redis.StrongName.1.2.1\lib\net45\StackExchange.Redis.StrongName.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="StackifyHttpTracer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=93c44ce23f2048dd, processorArchitecture=MSIL">
<HintPath>..\packages\StackifyHttpModule.1.0.28.0\lib\net45\StackifyHttpTracer.dll</HintPath>
</Reference>
@@ -60,6 +69,7 @@
<Reference Include="System.DirectoryServices" />
<Reference Include="System.DirectoryServices.AccountManagement" />
<Reference Include="System.Drawing" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Abstractions">
@@ -172,6 +182,7 @@
<Compile Include="DAL\MessagesManager.cs" />
<Compile Include="DAL\LogItemsManager.cs" />
<Compile Include="DAL\LabelsManager.cs" />
<Compile Include="Helpers\RedisStore.cs" />
<Compile Include="Helpers\CacheManager.cs" />
<Compile Include="Helpers\Config.cs" />
<Compile Include="BLL\Culture.cs" />
@@ -2,5 +2,7 @@
<packages>
<package id="Dapper" version="1.50.2" targetFramework="net451" />
<package id="ImageResizer" version="4.0.5" targetFramework="net451" />
<package id="Microsoft.Web.RedisOutputCacheProvider" version="1.7.5" targetFramework="net451" />
<package id="StackExchange.Redis.StrongName" version="1.2.1" targetFramework="net451" />
<package id="StackifyHttpModule" version="1.0.28.0" targetFramework="net451" />
</packages>
@@ -8,41 +8,55 @@
<add name="pigeoncms" connectionString="Data Source=.\ex20082;Initial Catalog=pigeoncms;Persist Security Info=True;User ID=sa;Pwd=sasasa777" providerName="System.Data.SqlClient"/>
<add name="demo" connectionString="Data Source=.\ex20082;Initial Catalog=demo;Persist Security Info=True;User ID=sa;Pwd=sasasa777" providerName="System.Data.SqlClient"/>
<add name="Dev" connectionString="Data Source=.\ex20082;Initial Catalog=dev;User ID=sa;Pwd=sasasa777" providerName="System.Data.SqlClient"/>
<add name="picce-demo" connectionString="Data Source=aqweb12;Initial Catalog=pigeon_test;Persist Security Info=True;User ID=sa;Pwd=KHFKJ87653shdgf" providerName="System.Data.SqlClient"/>
</connectionStrings>
<appSettings>
<add key="IsPigeonBundle" value="true"/>
<add key="ConnectionStringName" value="pigeoncms"/>
<add key="ConnectionStringName" value="picce-demo"/>
<add key="ProviderName" value="System.Data.SqlClient"/>
<add key="AddPageSuffix" value="false"/>
<add key="TabPrefix" value="pgn_"/>
<add key="TabPrefix" value="dev_"/>
<add key="DocsPublicPath" value="~/public/Docs/"/>
<add key="SessionTimeOutUrl" value="~/Default.aspx?act=timeout"/>
<add key="defaultCacheValue" value="60"/>
<add key="CultureDefault" value="it-IT"/>
<add key="CultureDev" value="it-IT"/>
<add key="EncryptKey" value="18KEU44ZBX"/>
<add key="RedisConnection" value="localhost:6379"/>
<add key="RedisAppName" value="PgnTest"/>
<add key="RedisDefaultExpireSeconds" value="600"/>
</appSettings>
<system.web>
<httpRuntime requestValidationMode="2.0"/>
<caching>
<outputCache defaultProvider="PigeonRedisOutputCache">
<providers>
<!-- https://docs.microsoft.com/it-it/azure/redis-cache/cache-aspnet-output-cache-provider-->
<!--<add name="MyRedisOutputCache" type="Microsoft.Web.Redis.RedisOutputCacheProvider" host="127.0.0.1" accessKey="" ssl="false"/>-->
</providers>
</outputCache>
</caching>
<membership defaultProvider="PgnUserProvider" userIsOnlineTimeWindow="15">
<providers>
<clear/>
<!--passwordFormat: Clear|Encrypted|Hashed-->
<add name="PgnUserProvider" type="PigeonCms.PgnUserProvider" connectionStringName="NynfaDev" applicationName="PigeonCms" enablePasswordRetrieval="false" enablePasswordReset="true" minRequiredPasswordLength="6" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Clear"/>
<add name="PgnUserProvider" type="PigeonCms.PgnUserProvider" connectionStringName="picce-demo" applicationName="PigeonCms" enablePasswordRetrieval="false" enablePasswordReset="true" minRequiredPasswordLength="6" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Clear"/>
<add name="ActiveDirectoryUserProvider" type="PigeonCms.ActiveDirectoryUserProvider" contextUsername="guest" contextPassword="guest" domain="YOURDOMAIN.local" applicationName="PigeonCms"/>
</providers>
</membership>
<roleManager defaultProvider="PgnRoleProvider" enabled="true" cacheRolesInCookie="true">
<providers>
<clear/>
<add name="PgnRoleProvider" type="PigeonCms.PgnRoleProvider" connectionStringName="NynfaDev" applicationName="PigeonCms"/>
<add name="PgnRoleProvider" type="PigeonCms.PgnRoleProvider" connectionStringName="picce-demo" applicationName="PigeonCms"/>
<add name="ActiveDirectoryRoleProvider" type="PigeonCms.ActiveDirectoryRoleProvider" contextUsername="guest" contextPassword="guest" domain="YOURDOMAIN.local" applicationName="PigeonCms"/>
</providers>
</roleManager>
</system.web>
<location path="Admin">
<system.web>
Oops, something went wrong.

0 comments on commit 6834056

Please sign in to comment.