diff --git a/src/Orchard.Web/Modules/Orchard.Caching/Services/DefaultCacheService.cs b/src/Orchard.Web/Modules/Orchard.Caching/Services/DefaultCacheService.cs
index af53e4b65..db2f5a779 100644
--- a/src/Orchard.Web/Modules/Orchard.Caching/Services/DefaultCacheService.cs
+++ b/src/Orchard.Web/Modules/Orchard.Caching/Services/DefaultCacheService.cs
@@ -4,7 +4,6 @@ using Orchard.Environment.Configuration;
namespace Orchard.Caching.Services {
///
/// Provides a per tenant implementation.
- /// Default timeout is 20 minutes.
///
public class DefaultCacheService : ICacheService {
private readonly ICacheStorageProvider _cacheStorageProvider;
@@ -17,7 +16,7 @@ namespace Orchard.Caching.Services {
_prefix = shellSettings.Name;
}
- public T Get(string key) {
+ public object Get(string key) {
return _cacheStorageProvider.Get(BuildFullKey(key));
}
diff --git a/src/Orchard.Web/Modules/Orchard.Caching/Services/DefaultCacheStorageProvider.cs b/src/Orchard.Web/Modules/Orchard.Caching/Services/DefaultCacheStorageProvider.cs
index c90e6e49d..a9db8a565 100644
--- a/src/Orchard.Web/Modules/Orchard.Caching/Services/DefaultCacheStorageProvider.cs
+++ b/src/Orchard.Web/Modules/Orchard.Caching/Services/DefaultCacheStorageProvider.cs
@@ -39,14 +39,16 @@ namespace Orchard.Caching.Services {
}
}
- public T Get(string key) {
- var value = _cache.Get(key) ;
+ public object Get(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) {
diff --git a/src/Orchard.Web/Modules/Orchard.Caching/Services/ICacheService.cs b/src/Orchard.Web/Modules/Orchard.Caching/Services/ICacheService.cs
index 03aeede41..f0437b4ec 100644
--- a/src/Orchard.Web/Modules/Orchard.Caching/Services/ICacheService.cs
+++ b/src/Orchard.Web/Modules/Orchard.Caching/Services/ICacheService.cs
@@ -2,7 +2,7 @@
namespace Orchard.Caching.Services {
public interface ICacheService : IDependency {
- T Get(string key);
+ object Get(string key);
void Put(string key, T value);
void Put(string key, T value, TimeSpan validFor);
@@ -12,8 +12,9 @@ namespace Orchard.Caching.Services {
}
public static class CachingExtensions {
- public static T Get(this ICacheService cacheService, string key, Func factory) {
+ public static object Get(this ICacheService cacheService, string key, Func factory) {
var result = cacheService.Get(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(this ICacheService cacheService, string key, Func factory, TimeSpan validFor) {
+ public static object Get(this ICacheService cacheService, string key, Func factory, TimeSpan validFor) {
var result = cacheService.Get(key);
+
if (result == null) {
var computed = factory();
cacheService.Put(key, computed, validFor);
diff --git a/src/Orchard.Web/Modules/Orchard.Caching/Services/ICacheStorageProvider.cs b/src/Orchard.Web/Modules/Orchard.Caching/Services/ICacheStorageProvider.cs
index 60253600f..4be4dc974 100644
--- a/src/Orchard.Web/Modules/Orchard.Caching/Services/ICacheStorageProvider.cs
+++ b/src/Orchard.Web/Modules/Orchard.Caching/Services/ICacheStorageProvider.cs
@@ -2,7 +2,7 @@
namespace Orchard.Caching.Services {
public interface ICacheStorageProvider : IDependency {
- T Get(string key);
+ object Get(string key);
void Put(string key, T value);
void Put(string key, T value, TimeSpan validFor);
void Remove(string key);