mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
Adding experimental support for Redis output cache
This commit is contained in:
parent
a6a59dcb75
commit
4a481ed5ab
@ -258,6 +258,12 @@ Website: http://www.microsoft.com
|
|||||||
Copyright: Copyright Microsoft Corporation
|
Copyright: Copyright Microsoft Corporation
|
||||||
License: Custom EULA - http://www.microsoft.com/web/webpi/eula/microsoft_web_xmltransform.htm
|
License: Custom EULA - http://www.microsoft.com/web/webpi/eula/microsoft_web_xmltransform.htm
|
||||||
|
|
||||||
|
StackExchange.Redis
|
||||||
|
------
|
||||||
|
Websites: https://github.com/StackExchange/StackExchange.Redis
|
||||||
|
Copyright: Copyright (c) 2014 Stack Exchange
|
||||||
|
License: MIT - https://raw.githubusercontent.com/StackExchange/StackExchange.Redis/master/LICENSE
|
||||||
|
|
||||||
SlowCheetah
|
SlowCheetah
|
||||||
-----
|
-----
|
||||||
Website: https://github.com/sayedihashimi/package-web/
|
Website: https://github.com/sayedihashimi/package-web/
|
||||||
|
47
lib/redis/LICENSE.txt
Normal file
47
lib/redis/LICENSE.txt
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2014 Stack Exchange
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
===============================================
|
||||||
|
|
||||||
|
Third Party Licenses:
|
||||||
|
|
||||||
|
The Redis project (http://redis.io/) is independent of this client library, and
|
||||||
|
is licensed separately under the three clause BSD license. The full license
|
||||||
|
information can be viewed here: http://redis.io/topics/license
|
||||||
|
|
||||||
|
This tool makes use of the "redis-doc" library from http://redis.io/documentation
|
||||||
|
in the intellisense comments, which is licensed under the
|
||||||
|
Creative Commons Attribution-ShareAlike 4.0 International license; full
|
||||||
|
details are available here:
|
||||||
|
https://github.com/antirez/redis-doc/blob/master/COPYRIGHT
|
||||||
|
|
||||||
|
The development solution uses the Redis-64 package from nuget
|
||||||
|
(https://www.nuget.org/packages/Redis-64) by Microsoft Open Technologies, inc.
|
||||||
|
This is licensed under the BSD license; full details are available here:
|
||||||
|
https://github.com/MSOpenTech/redis/blob/2.6/license.txt
|
||||||
|
This tool is not used in the release binaries.
|
||||||
|
|
||||||
|
The development solution uses the BookSleeve package from nuget
|
||||||
|
(https://code.google.com/p/booksleeve/) by Marc Gravell. This is licensed
|
||||||
|
under the Apache 2.0 license; full details are available here:
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
This tool is not used in the release binaries.
|
BIN
lib/redis/StackExchange.Redis.dll
Normal file
BIN
lib/redis/StackExchange.Redis.dll
Normal file
Binary file not shown.
BIN
lib/redis/StackExchange.Redis.pdb
Normal file
BIN
lib/redis/StackExchange.Redis.pdb
Normal file
Binary file not shown.
4772
lib/redis/StackExchange.Redis.xml
Normal file
4772
lib/redis/StackExchange.Redis.xml
Normal file
File diff suppressed because it is too large
Load Diff
@ -17,6 +17,11 @@ Features:
|
|||||||
Description: Activates an Orchard output cache provider that targets Windows Azure Cache.
|
Description: Activates an Orchard output cache provider that targets Windows Azure Cache.
|
||||||
Dependencies: Orchard.Azure, Orchard.OutputCache
|
Dependencies: Orchard.Azure, Orchard.OutputCache
|
||||||
Category: Performance
|
Category: Performance
|
||||||
|
Orchard.Azure.RedisOutputCache:
|
||||||
|
Name: Microsoft Azure Redis Output Cache
|
||||||
|
Description: Activates an Orchard output cache provider that targets Windows Azure Redis Cache.
|
||||||
|
Dependencies: Orchard.Azure, Orchard.OutputCache
|
||||||
|
Category: Performance
|
||||||
Orchard.Azure.DatabaseCache:
|
Orchard.Azure.DatabaseCache:
|
||||||
Name: Microsoft Azure Database Cache
|
Name: Microsoft Azure Database Cache
|
||||||
Description: Activates an NHibernate second-level cache provider that targets Microsoft Azure Cache.
|
Description: Activates an NHibernate second-level cache provider that targets Microsoft Azure Cache.
|
||||||
|
@ -85,10 +85,17 @@
|
|||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>..\..\..\..\lib\windowsazure\Microsoft.WindowsAzure.Storage.dll</HintPath>
|
<HintPath>..\..\..\..\lib\windowsazure\Microsoft.WindowsAzure.Storage.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\..\..\..\lib\newtonsoft.json\Newtonsoft.Json.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="NHibernate, Version=3.3.1.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
|
<Reference Include="NHibernate, Version=3.3.1.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>..\..\..\..\lib\nhibernate\NHibernate.dll</HintPath>
|
<HintPath>..\..\..\..\lib\nhibernate\NHibernate.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="StackExchange.Redis">
|
||||||
|
<HintPath>..\..\..\..\lib\redis\StackExchange.Redis.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Configuration" />
|
<Reference Include="System.Configuration" />
|
||||||
<Reference Include="System.Web" />
|
<Reference Include="System.Web" />
|
||||||
@ -101,6 +108,7 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Services\Caching\Output\AzureRedisOutputCacheStorageProvider.cs" />
|
||||||
<Compile Include="Services\Environment\Configuration\DefaultPlatformConfigurationAccessor.cs" />
|
<Compile Include="Services\Environment\Configuration\DefaultPlatformConfigurationAccessor.cs" />
|
||||||
<Compile Include="Services\Environment\Configuration\IPlatformConfigurationAccessor.cs" />
|
<Compile Include="Services\Environment\Configuration\IPlatformConfigurationAccessor.cs" />
|
||||||
<Compile Include="Services\TaskLease\AzureMachineNameProvider.cs" />
|
<Compile Include="Services\TaskLease\AzureMachineNameProvider.cs" />
|
||||||
|
@ -0,0 +1,121 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
|
using Microsoft.ApplicationServer.Caching;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Orchard.Azure.Services.Environment.Configuration;
|
||||||
|
using Orchard.Caching;
|
||||||
|
using Orchard.Environment.Configuration;
|
||||||
|
using Orchard.Environment.Extensions;
|
||||||
|
using Orchard.Logging;
|
||||||
|
using Orchard.OutputCache.Models;
|
||||||
|
using Orchard.OutputCache.Services;
|
||||||
|
using StackExchange.Redis;
|
||||||
|
|
||||||
|
namespace Orchard.Azure.Services.Caching.Output {
|
||||||
|
|
||||||
|
[OrchardFeature("Orchard.Azure.RedisOutputCache")]
|
||||||
|
[OrchardSuppressDependency("Orchard.OutputCache.Services.DefaultCacheStorageProvider")]
|
||||||
|
public class AzureRedisCacheStorageProvider : Component, IOutputCacheStorageProvider {
|
||||||
|
public const string DataCacheKey = "DataCache";
|
||||||
|
public const string ClientConfigurationKey = "CacheClientConfiguration";
|
||||||
|
|
||||||
|
private CacheClientConfiguration _cacheClientConfiguration;
|
||||||
|
private static ConcurrentDictionary<CacheClientConfiguration, ConnectionMultiplexer> _connectionMultiplexers = new ConcurrentDictionary<CacheClientConfiguration, ConnectionMultiplexer>();
|
||||||
|
|
||||||
|
private readonly ICacheManager _cacheManager;
|
||||||
|
private readonly ShellSettings _shellSettings;
|
||||||
|
private readonly IPlatformConfigurationAccessor _pca;
|
||||||
|
|
||||||
|
public AzureRedisCacheStorageProvider(
|
||||||
|
ShellSettings shellSettings,
|
||||||
|
IPlatformConfigurationAccessor pca,
|
||||||
|
ICacheManager cacheManager) {
|
||||||
|
_cacheManager = cacheManager;
|
||||||
|
_shellSettings = shellSettings;
|
||||||
|
_pca = pca;
|
||||||
|
|
||||||
|
Logger = NullLogger.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CacheClientConfiguration CacheConfiguration {
|
||||||
|
get {
|
||||||
|
// the configuration is backed by a field so that we don't call the cacheManager multiple times in the same request
|
||||||
|
// cache configurations are stored in the cacheManager so that we don't read the config on each request
|
||||||
|
if (_cacheClientConfiguration == null) {
|
||||||
|
|
||||||
|
_cacheClientConfiguration = _cacheManager.Get(ClientConfigurationKey, ctx => {
|
||||||
|
CacheClientConfiguration cacheConfig;
|
||||||
|
try {
|
||||||
|
cacheConfig = CacheClientConfiguration.FromPlatformConfiguration(
|
||||||
|
_shellSettings.Name,
|
||||||
|
Constants.OutputCacheSettingNamePrefix,
|
||||||
|
_pca);
|
||||||
|
|
||||||
|
cacheConfig.Validate();
|
||||||
|
return cacheConfig;
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
throw new Exception(String.Format("The {0} configuration settings are missing or invalid.", Constants.OutputCacheFeatureName), ex);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (_cacheClientConfiguration == null) {
|
||||||
|
throw new InvalidOperationException("Could not create a valid cache configuration");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return _cacheClientConfiguration;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IDatabase Cache {
|
||||||
|
get {
|
||||||
|
|
||||||
|
var connectionMultiplexer = _connectionMultiplexers.GetOrAdd(CacheConfiguration, cfg => {
|
||||||
|
Logger.Debug("Creating a new cache client ({0})", CacheConfiguration.GetHashCode());
|
||||||
|
var connectionString = cfg.HostIdentifier + ",password=" + cfg.AuthorizationToken;
|
||||||
|
return ConnectionMultiplexer.Connect(connectionString);
|
||||||
|
});
|
||||||
|
|
||||||
|
return connectionMultiplexer.GetDatabase();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Set(string key, CacheItem cacheItem) {
|
||||||
|
if (cacheItem.ValidFor <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var value = JsonConvert.SerializeObject(cacheItem);
|
||||||
|
Cache.StringSet(key, value, TimeSpan.FromSeconds(cacheItem.ValidFor));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Remove(string key) {
|
||||||
|
Cache.StringSet(key, String.Empty, TimeSpan.MinValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveAll() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public CacheItem GetCacheItem(string key) {
|
||||||
|
string value = Cache.StringGet(key);
|
||||||
|
if(String.IsNullOrEmpty(value)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return JsonConvert.DeserializeObject<CacheItem>(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<CacheItem> GetCacheItems(int skip, int count) {
|
||||||
|
|
||||||
|
return Enumerable.Empty<CacheItem>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetCacheItemsCount() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user