mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
@@ -4,7 +4,6 @@ using Orchard.Environment.Configuration;
|
||||
namespace Orchard.Caching.Services {
|
||||
/// <summary>
|
||||
/// Provides a per tenant <see cref="ICacheService"/> implementation.
|
||||
/// Default timeout is 20 minutes.
|
||||
/// </summary>
|
||||
public class DefaultCacheService : ICacheService {
|
||||
private readonly ICacheStorageProvider _cacheStorageProvider;
|
||||
@@ -17,7 +16,7 @@ namespace Orchard.Caching.Services {
|
||||
_prefix = shellSettings.Name;
|
||||
}
|
||||
|
||||
public T Get<T>(string key) {
|
||||
public object Get<T>(string key) {
|
||||
return _cacheStorageProvider.Get<T>(BuildFullKey(key));
|
||||
}
|
||||
|
||||
|
||||
@@ -39,14 +39,16 @@ namespace Orchard.Caching.Services {
|
||||
}
|
||||
}
|
||||
|
||||
public T Get<T>(string key) {
|
||||
var value = _cache.Get(key) ;
|
||||
public object Get<T>(string key) {
|
||||
var value = _cache.Get(key);
|
||||
|
||||
// if the provided expression is non-null, and the provided object can
|
||||
// be cast to the provided type without causing an exception to be thrown
|
||||
if(value is T) {
|
||||
return (T)value;
|
||||
}
|
||||
|
||||
return default(T);
|
||||
return null;
|
||||
}
|
||||
|
||||
private CacheItemPolicy GetCacheItemPolicy(DateTimeOffset absoluteExpiration) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Orchard.Caching.Services {
|
||||
public interface ICacheService : IDependency {
|
||||
T Get<T>(string key);
|
||||
object Get<T>(string key);
|
||||
|
||||
void Put<T>(string key, T value);
|
||||
void Put<T>(string key, T value, TimeSpan validFor);
|
||||
@@ -12,8 +12,9 @@ namespace Orchard.Caching.Services {
|
||||
}
|
||||
|
||||
public static class CachingExtensions {
|
||||
public static T Get<T>(this ICacheService cacheService, string key, Func<T> factory) {
|
||||
public static object Get<T>(this ICacheService cacheService, string key, Func<T> factory) {
|
||||
var result = cacheService.Get<T>(key);
|
||||
|
||||
if (result == null) {
|
||||
var computed = factory();
|
||||
cacheService.Put(key, computed);
|
||||
@@ -24,8 +25,9 @@ namespace Orchard.Caching.Services {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static T Get<T>(this ICacheService cacheService, string key, Func<T> factory, TimeSpan validFor) {
|
||||
public static object Get<T>(this ICacheService cacheService, string key, Func<T> factory, TimeSpan validFor) {
|
||||
var result = cacheService.Get<T>(key);
|
||||
|
||||
if (result == null) {
|
||||
var computed = factory();
|
||||
cacheService.Put(key, computed, validFor);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Orchard.Caching.Services {
|
||||
public interface ICacheStorageProvider : IDependency {
|
||||
T Get<T>(string key);
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user