mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Fixing style
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using Newtonsoft.Json;
|
||||
using Orchard;
|
||||
using Orchard.Caching.Services;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Environment.Extensions;
|
||||
@@ -9,62 +8,55 @@ using Orchard.Redis.Extensions;
|
||||
using StackExchange.Redis;
|
||||
using System;
|
||||
|
||||
namespace Orchard.Redis.Caching
|
||||
{
|
||||
[OrchardFeature("Orchard.Redis.Caching")]
|
||||
[OrchardSuppressDependency("Orchard.Caching.Services.DefaultCacheStorageProvider")]
|
||||
public class RedisCacheStorageProvider : Component, ICacheStorageProvider
|
||||
{
|
||||
public const string ConnectionStringKey = "Orchard.Redis.Cache";
|
||||
namespace Orchard.Redis.Caching {
|
||||
|
||||
private readonly ShellSettings _shellSettings;
|
||||
private readonly IRedisConnectionProvider _redisConnectionProvider;
|
||||
private readonly string _connectionString;
|
||||
[OrchardFeature("Orchard.Redis.Caching")]
|
||||
[OrchardSuppressDependency("Orchard.Caching.Services.DefaultCacheStorageProvider")]
|
||||
public class RedisCacheStorageProvider : Component, ICacheStorageProvider {
|
||||
public const string ConnectionStringKey = "Orchard.Redis.Cache";
|
||||
|
||||
public IDatabase Database {
|
||||
get {
|
||||
return _redisConnectionProvider.GetConnection(_connectionString).GetDatabase();
|
||||
private readonly ShellSettings _shellSettings;
|
||||
private readonly IRedisConnectionProvider _redisConnectionProvider;
|
||||
private readonly string _connectionString;
|
||||
|
||||
public IDatabase Database {
|
||||
get {
|
||||
return _redisConnectionProvider.GetConnection(_connectionString).GetDatabase();
|
||||
}
|
||||
}
|
||||
|
||||
public RedisCacheStorageProvider(ShellSettings shellSettings, IRedisConnectionProvider redisConnectionProvider) {
|
||||
_shellSettings = shellSettings;
|
||||
_redisConnectionProvider = redisConnectionProvider;
|
||||
_connectionString = _redisConnectionProvider.GetConnectionString(ConnectionStringKey);
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
|
||||
public T Get<T>(string key) {
|
||||
var json = Database.StringGet(GetLocalizedKey(key));
|
||||
return JsonConvert.DeserializeObject<T>(json);
|
||||
}
|
||||
|
||||
public void Put<T>(string key, T value) {
|
||||
var json = JsonConvert.SerializeObject(value);
|
||||
Database.StringSet(GetLocalizedKey(key), json, null);
|
||||
}
|
||||
|
||||
public void Put<T>(string key, T value, TimeSpan validFor) {
|
||||
var json = JsonConvert.SerializeObject(value);
|
||||
Database.StringSet(GetLocalizedKey(key), json, validFor);
|
||||
}
|
||||
|
||||
public void Remove(string key) {
|
||||
Database.KeyDelete(key);
|
||||
}
|
||||
|
||||
public void Clear() {
|
||||
Database.KeyDeleteWithPrefix(GetLocalizedKey("*"));
|
||||
}
|
||||
|
||||
private string GetLocalizedKey(string key) {
|
||||
return _shellSettings.Name + ":Cache:" + key;
|
||||
}
|
||||
}
|
||||
|
||||
public RedisCacheStorageProvider(ShellSettings shellSettings, IRedisConnectionProvider redisConnectionProvider)
|
||||
{
|
||||
_shellSettings = shellSettings;
|
||||
_redisConnectionProvider = redisConnectionProvider;
|
||||
_connectionString = _redisConnectionProvider.GetConnectionString(ConnectionStringKey);
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
|
||||
public T Get<T>(string key) {
|
||||
var json = Database.StringGet(GetLocalizedKey(key));
|
||||
return JsonConvert.DeserializeObject<T>(json);
|
||||
}
|
||||
|
||||
public void Put<T>(string key, T value)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(value);
|
||||
Database.StringSet(GetLocalizedKey(key), json, null);
|
||||
}
|
||||
|
||||
public void Put<T>(string key, T value, TimeSpan validFor)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(value);
|
||||
Database.StringSet(GetLocalizedKey(key), json, validFor);
|
||||
}
|
||||
|
||||
public void Remove(string key)
|
||||
{
|
||||
Database.KeyDelete(key);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
Database.KeyDeleteWithPrefix(GetLocalizedKey("*"));
|
||||
}
|
||||
|
||||
private string GetLocalizedKey(string key)
|
||||
{
|
||||
return _shellSettings.Name + ":Cache:" + key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace Orchard.Redis.Configuration {
|
||||
|
||||
public interface IRedisConnectionProvider : ISingletonDependency {
|
||||
|
||||
ConnectionMultiplexer GetConnection(string connectionString);
|
||||
|
||||
string GetConnectionString(string service);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ using Orchard.Logging;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace Orchard.Redis.Configuration {
|
||||
|
||||
public class RedisConnectionProvider : IRedisConnectionProvider {
|
||||
private static ConcurrentDictionary<string, ConnectionMultiplexer> _connectionMultiplexers = new ConcurrentDictionary<string, ConnectionMultiplexer>();
|
||||
private readonly ShellSettings _shellSettings;
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
using System;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace Orchard.Redis.Extensions
|
||||
{
|
||||
public static class RedisDatabaseExtensions
|
||||
{
|
||||
public static void KeyDeleteWithPrefix(this IDatabase database, string prefix)
|
||||
{
|
||||
namespace Orchard.Redis.Extensions {
|
||||
public static class RedisDatabaseExtensions {
|
||||
public static void KeyDeleteWithPrefix(this IDatabase database, string prefix) {
|
||||
if (database == null) {
|
||||
throw new ArgumentException("Database cannot be null", "database");
|
||||
}
|
||||
@@ -33,8 +30,9 @@ namespace Orchard.Redis.Extensions
|
||||
|
||||
var retVal = database.ScriptEvaluate("return table.getn(redis.call('keys', ARGV[1]))", values: new RedisValue[] { prefix });
|
||||
|
||||
if (retVal.IsNull)
|
||||
if (retVal.IsNull) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int)retVal;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ Version: 1.0
|
||||
OrchardVersion: 1.0
|
||||
Description: Provides Redis integration with Orchard.
|
||||
Features:
|
||||
Orchard.Redis
|
||||
Orchard.Redis
|
||||
Name: Redis
|
||||
Description: Used to provide Redis related functionalities.
|
||||
Category: Hosting
|
||||
@@ -14,13 +14,13 @@ Features:
|
||||
Name: Redis Message Bus
|
||||
Description: A message bus implementation using Redis pub/sub.
|
||||
Category: Hosting
|
||||
Dependencies: Orchard.MessageBus, Orchard.Redis
|
||||
Orchard.Redis.OutputCache:
|
||||
Dependencies: Orchard.MessageBus, Orchard.Redis
|
||||
Orchard.Redis.OutputCache:
|
||||
Name: Redis Output Cache
|
||||
Description: An output cache storage provider using Redis.
|
||||
Category: Performance
|
||||
Dependencies: Orchard.OutputCache, Orchard.Redis
|
||||
Orchard.Redis.Caching:
|
||||
Orchard.Redis.Caching:
|
||||
Name: Redis Cache
|
||||
Description: Business data cache using Redis.
|
||||
Category: Performance
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace Orchard.Redis.OutputCache {
|
||||
var value = JsonConvert.SerializeObject(cacheItem);
|
||||
Database.StringSet(GetLocalizedKey(key), value, TimeSpan.FromSeconds(cacheItem.ValidFor));
|
||||
}
|
||||
|
||||
|
||||
public void Remove(string key) {
|
||||
Database.KeyDelete(GetLocalizedKey(key));
|
||||
}
|
||||
@@ -57,7 +57,7 @@ namespace Orchard.Redis.OutputCache {
|
||||
|
||||
public CacheItem GetCacheItem(string key) {
|
||||
string value = Database.StringGet(GetLocalizedKey(key));
|
||||
if(String.IsNullOrEmpty(value)) {
|
||||
if (String.IsNullOrEmpty(value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user