mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Applied Zoltan's suggestions (see comments on work item).
Work Item: #21068
This commit is contained in:
@@ -1,26 +1,31 @@
|
||||
using System;
|
||||
using Orchard.Caching.Services;
|
||||
|
||||
namespace Orchard.Caching.Helpers {
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace Orchard.Caching {
|
||||
public static class CachingExtensions {
|
||||
public static T GetValue<T>(this ICacheStorageProvider provider, string key) {
|
||||
public static T Get<T>(this ICacheStorageProvider provider, string key) {
|
||||
return (T)provider.Get<T>(key);
|
||||
}
|
||||
|
||||
public static T GetValue<T>(this ICacheService cacheService, string key) {
|
||||
return GetValue<T>(cacheService, key, null);
|
||||
public static object Get(this ICacheService cacheService, string key) {
|
||||
return cacheService.Get<object>(key);
|
||||
}
|
||||
|
||||
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) {
|
||||
return Get<T>(cacheService, key, null);
|
||||
}
|
||||
|
||||
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, TimeSpan validFor) {
|
||||
return Get<T>(cacheService, key, null, validFor);
|
||||
}
|
||||
|
||||
public static T GetValue<T>(this ICacheService cacheService, string key, Func<T> factory, TimeSpan validFor) {
|
||||
var result = cacheService.Get<T>(key);
|
||||
public static T Get<T>(this ICacheService cacheService, string key, Func<T> factory) {
|
||||
return Get(cacheService, key, factory, TimeSpan.MinValue);
|
||||
}
|
||||
|
||||
public static T Get<T>(this ICacheService cacheService, string key, Func<T> factory, TimeSpan validFor) {
|
||||
var result = cacheService.GetObject<T>(key);
|
||||
|
||||
if (result == null && factory != null) {
|
||||
var computed = factory();
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Orchard.Caching.Services {
|
||||
_prefix = shellSettings.Name;
|
||||
}
|
||||
|
||||
public object Get<T>(string key) {
|
||||
public object GetObject<T>(string key) {
|
||||
return _cacheStorageProvider.Get<T>(BuildFullKey(key));
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Orchard.Caching.Services {
|
||||
public interface ICacheService : IDependency {
|
||||
object Get<T>(string key);
|
||||
object GetObject<T>(string key);
|
||||
|
||||
void Put<T>(string key, T value);
|
||||
void Put<T>(string key, T value, TimeSpan validFor);
|
||||
|
||||
Reference in New Issue
Block a user