mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Adding back <T> argument for serialization purposes and updating extension methods to disambiguate between "object Get<T>(string)" and "T Get<T>(string)".
This commit is contained in:
@@ -3,24 +3,24 @@ using Orchard.Caching.Services;
|
||||
|
||||
namespace Orchard.Caching.Helpers {
|
||||
public static class CachingExtensions {
|
||||
public static T Get<T>(this ICacheStorageProvider provider, string key) {
|
||||
return (T)provider.Get(key);
|
||||
public static T GetValue<T>(this ICacheStorageProvider provider, string key) {
|
||||
return (T)provider.Get<T>(key);
|
||||
}
|
||||
|
||||
public static T Get<T>(this ICacheService cacheService, string key) {
|
||||
return Get<T>(cacheService, key, null);
|
||||
public static T GetValue<T>(this ICacheService cacheService, string key) {
|
||||
return GetValue<T>(cacheService, key, null);
|
||||
}
|
||||
|
||||
public static T Get<T>(this ICacheService cacheService, string key, TimeSpan validFor) {
|
||||
return Get<T>(cacheService, key, null, validFor);
|
||||
public static T GetValue<T>(this ICacheService cacheService, string key, TimeSpan validFor) {
|
||||
return GetValue<T>(cacheService, key, null, validFor);
|
||||
}
|
||||
|
||||
public static T Get<T>(this ICacheService cacheService, string key, Func<T> factory) {
|
||||
return Get(cacheService, key, factory, TimeSpan.MinValue);
|
||||
public static T GetValue<T>(this ICacheService cacheService, string key, Func<T> factory) {
|
||||
return GetValue(cacheService, key, factory, TimeSpan.MinValue);
|
||||
}
|
||||
|
||||
public static T Get<T>(this ICacheService cacheService, string key, Func<T> factory, TimeSpan validFor) {
|
||||
var result = cacheService.Get(key);
|
||||
public static T GetValue<T>(this ICacheService cacheService, string key, Func<T> factory, TimeSpan validFor) {
|
||||
var result = cacheService.Get<T>(key);
|
||||
|
||||
if (result == null && factory != null) {
|
||||
var computed = factory();
|
||||
|
@@ -8,4 +8,4 @@ Description: Provides an API to cache business data.
|
||||
Features:
|
||||
Orchard.Caching:
|
||||
Description: Provides an API to cache business data.
|
||||
Category: Performance
|
||||
Category: Performance
|
@@ -16,15 +16,15 @@ namespace Orchard.Caching.Services {
|
||||
_prefix = shellSettings.Name;
|
||||
}
|
||||
|
||||
public object Get(string key) {
|
||||
return _cacheStorageProvider.Get(BuildFullKey(key));
|
||||
public object Get<T>(string key) {
|
||||
return _cacheStorageProvider.Get<T>(BuildFullKey(key));
|
||||
}
|
||||
|
||||
public void Put(string key, object value) {
|
||||
public void Put<T>(string key, T value) {
|
||||
_cacheStorageProvider.Put(BuildFullKey(key), value);
|
||||
}
|
||||
|
||||
public void Put(string key, object value, TimeSpan validFor) {
|
||||
public void Put<T>(string key, T value, TimeSpan validFor) {
|
||||
_cacheStorageProvider.Put(BuildFullKey(key), value, validFor);
|
||||
}
|
||||
|
||||
|
@@ -17,12 +17,12 @@ namespace Orchard.Caching.Services {
|
||||
_clock = clock;
|
||||
}
|
||||
|
||||
public void Put(string key, object value) {
|
||||
public void Put<T>(string key, T value) {
|
||||
// Keys are already prefixed by DefaultCacheService so no need to do it here again.
|
||||
_cache.Set(key, value, GetCacheItemPolicy(ObjectCache.InfiniteAbsoluteExpiration));
|
||||
}
|
||||
|
||||
public void Put(string key, object value, TimeSpan validFor) {
|
||||
public void Put<T>(string key, T value, TimeSpan validFor) {
|
||||
_cache.Set(key, value, GetCacheItemPolicy(new DateTimeOffset(_clock.UtcNow).ToOffset(validFor)));
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Orchard.Caching.Services {
|
||||
}
|
||||
}
|
||||
|
||||
public object Get(string key) {
|
||||
public object Get<T>(string key) {
|
||||
return _cache.Get(key);
|
||||
}
|
||||
|
||||
|
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace Orchard.Caching.Services {
|
||||
public interface ICacheService : IDependency {
|
||||
object Get(string key);
|
||||
object Get<T>(string key);
|
||||
|
||||
void Put(string key, object value);
|
||||
void Put(string key, object value, TimeSpan validFor);
|
||||
void Put<T>(string key, T value);
|
||||
void Put<T>(string key, T value, TimeSpan validFor);
|
||||
|
||||
void Remove(string key);
|
||||
void Clear();
|
||||
|
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace Orchard.Caching.Services {
|
||||
public interface ICacheStorageProvider : IDependency {
|
||||
object Get(string key);
|
||||
void Put(string key, object value);
|
||||
void Put(string key, object value, TimeSpan validFor);
|
||||
object Get<T>(string key);
|
||||
void Put<T>(string key, T value);
|
||||
void Put<T>(string key, T value, TimeSpan validFor);
|
||||
void Remove(string key);
|
||||
void Clear();
|
||||
}
|
||||
|
@@ -32,17 +32,17 @@ namespace Orchard.Redis.Caching {
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
|
||||
public object Get(string key) {
|
||||
public object Get<T>(string key) {
|
||||
var json = Database.StringGet(GetLocalizedKey(key));
|
||||
return JsonConvert.DeserializeObject(json);
|
||||
return JsonConvert.DeserializeObject<T>(json);
|
||||
}
|
||||
|
||||
public void Put(string key, object value) {
|
||||
public void Put<T>(string key, T value) {
|
||||
var json = JsonConvert.SerializeObject(value);
|
||||
Database.StringSet(GetLocalizedKey(key), json, null);
|
||||
}
|
||||
|
||||
public void Put(string key, object value, TimeSpan validFor) {
|
||||
public void Put<T>(string key, T value, TimeSpan validFor) {
|
||||
var json = JsonConvert.SerializeObject(value);
|
||||
Database.StringSet(GetLocalizedKey(key), json, validFor);
|
||||
}
|
||||
|
Reference in New Issue
Block a user