forked from alastairtree/LazyCache
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renamed AppCacheExtenions to AppCacheExtensions. (alastairtree#65)
- Loading branch information
1 parent
b685f00
commit ddb48e0
Showing
1 changed file
with
99 additions
and
99 deletions.
There are no files selected for viewing
198 changes: 99 additions & 99 deletions
198
LazyCache/AppCacheExtenions.cs → LazyCache/AppCacheExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,100 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Caching.Memory; | ||
|
||
namespace LazyCache | ||
{ | ||
public static class AppCacheExtenions | ||
{ | ||
public static void Add<T>(this IAppCache cache, string key, T item) | ||
{ | ||
if (cache == null) throw new ArgumentNullException(nameof(cache)); | ||
|
||
cache.Add(key, item, cache.DefaultCachePolicy.BuildOptions()); | ||
} | ||
|
||
public static void Add<T>(this IAppCache cache, string key, T item, DateTimeOffset expires) | ||
{ | ||
if (cache == null) throw new ArgumentNullException(nameof(cache)); | ||
|
||
cache.Add(key, item, new MemoryCacheEntryOptions {AbsoluteExpiration = expires}); | ||
} | ||
|
||
public static void Add<T>(this IAppCache cache, string key, T item, TimeSpan slidingExpiration) | ||
{ | ||
if (cache == null) throw new ArgumentNullException(nameof(cache)); | ||
|
||
cache.Add(key, item, new MemoryCacheEntryOptions {SlidingExpiration = slidingExpiration}); | ||
} | ||
|
||
public static T GetOrAdd<T>(this IAppCache cache, string key, Func<T> addItemFactory) | ||
{ | ||
if (cache == null) throw new ArgumentNullException(nameof(cache)); | ||
|
||
return cache.GetOrAdd(key, addItemFactory, cache.DefaultCachePolicy.BuildOptions()); | ||
} | ||
|
||
public static T GetOrAdd<T>(this IAppCache cache, string key, Func<T> addItemFactory, DateTimeOffset expires) | ||
{ | ||
if (cache == null) throw new ArgumentNullException(nameof(cache)); | ||
|
||
return cache.GetOrAdd(key, addItemFactory, new MemoryCacheEntryOptions {AbsoluteExpiration = expires}); | ||
} | ||
|
||
public static T GetOrAdd<T>(this IAppCache cache, string key, Func<T> addItemFactory, | ||
TimeSpan slidingExpiration) | ||
{ | ||
return cache.GetOrAdd(key, addItemFactory, | ||
new MemoryCacheEntryOptions {SlidingExpiration = slidingExpiration}); | ||
} | ||
|
||
public static T GetOrAdd<T>(this IAppCache cache, string key, Func<T> addItemFactory, | ||
MemoryCacheEntryOptions policy) | ||
{ | ||
if (cache == null) throw new ArgumentNullException(nameof(cache)); | ||
|
||
return cache.GetOrAdd(key, entry => | ||
{ | ||
entry.SetOptions(policy); | ||
return addItemFactory(); | ||
}); | ||
} | ||
|
||
public static Task<T> GetOrAddAsync<T>(this IAppCache cache, string key, Func<Task<T>> addItemFactory) | ||
{ | ||
if (cache == null) throw new ArgumentNullException(nameof(cache)); | ||
|
||
return cache.GetOrAddAsync(key, addItemFactory, cache.DefaultCachePolicy.BuildOptions()); | ||
} | ||
|
||
|
||
public static Task<T> GetOrAddAsync<T>(this IAppCache cache, string key, Func<Task<T>> addItemFactory, | ||
DateTimeOffset expires) | ||
{ | ||
if (cache == null) throw new ArgumentNullException(nameof(cache)); | ||
|
||
return cache.GetOrAddAsync(key, addItemFactory, new MemoryCacheEntryOptions {AbsoluteExpiration = expires}); | ||
} | ||
|
||
public static Task<T> GetOrAddAsync<T>(this IAppCache cache, string key, Func<Task<T>> addItemFactory, | ||
TimeSpan slidingExpiration) | ||
{ | ||
if (cache == null) throw new ArgumentNullException(nameof(cache)); | ||
|
||
return cache.GetOrAddAsync(key, addItemFactory, | ||
new MemoryCacheEntryOptions {SlidingExpiration = slidingExpiration}); | ||
} | ||
|
||
public static Task<T> GetOrAddAsync<T>(this IAppCache cache, string key, Func<Task<T>> addItemFactory, | ||
MemoryCacheEntryOptions policy) | ||
{ | ||
if (cache == null) throw new ArgumentNullException(nameof(cache)); | ||
|
||
return cache.GetOrAddAsync(key, entry => | ||
{ | ||
entry.SetOptions(policy); | ||
return addItemFactory(); | ||
}); | ||
} | ||
} | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Caching.Memory; | ||
|
||
namespace LazyCache | ||
{ | ||
public static class AppCacheExtensions | ||
{ | ||
public static void Add<T>(this IAppCache cache, string key, T item) | ||
{ | ||
if (cache == null) throw new ArgumentNullException(nameof(cache)); | ||
|
||
cache.Add(key, item, cache.DefaultCachePolicy.BuildOptions()); | ||
} | ||
|
||
public static void Add<T>(this IAppCache cache, string key, T item, DateTimeOffset expires) | ||
{ | ||
if (cache == null) throw new ArgumentNullException(nameof(cache)); | ||
|
||
cache.Add(key, item, new MemoryCacheEntryOptions {AbsoluteExpiration = expires}); | ||
} | ||
|
||
public static void Add<T>(this IAppCache cache, string key, T item, TimeSpan slidingExpiration) | ||
{ | ||
if (cache == null) throw new ArgumentNullException(nameof(cache)); | ||
|
||
cache.Add(key, item, new MemoryCacheEntryOptions {SlidingExpiration = slidingExpiration}); | ||
} | ||
|
||
public static T GetOrAdd<T>(this IAppCache cache, string key, Func<T> addItemFactory) | ||
{ | ||
if (cache == null) throw new ArgumentNullException(nameof(cache)); | ||
|
||
return cache.GetOrAdd(key, addItemFactory, cache.DefaultCachePolicy.BuildOptions()); | ||
} | ||
|
||
public static T GetOrAdd<T>(this IAppCache cache, string key, Func<T> addItemFactory, DateTimeOffset expires) | ||
{ | ||
if (cache == null) throw new ArgumentNullException(nameof(cache)); | ||
|
||
return cache.GetOrAdd(key, addItemFactory, new MemoryCacheEntryOptions {AbsoluteExpiration = expires}); | ||
} | ||
|
||
public static T GetOrAdd<T>(this IAppCache cache, string key, Func<T> addItemFactory, | ||
TimeSpan slidingExpiration) | ||
{ | ||
return cache.GetOrAdd(key, addItemFactory, | ||
new MemoryCacheEntryOptions {SlidingExpiration = slidingExpiration}); | ||
} | ||
|
||
public static T GetOrAdd<T>(this IAppCache cache, string key, Func<T> addItemFactory, | ||
MemoryCacheEntryOptions policy) | ||
{ | ||
if (cache == null) throw new ArgumentNullException(nameof(cache)); | ||
|
||
return cache.GetOrAdd(key, entry => | ||
{ | ||
entry.SetOptions(policy); | ||
return addItemFactory(); | ||
}); | ||
} | ||
|
||
public static Task<T> GetOrAddAsync<T>(this IAppCache cache, string key, Func<Task<T>> addItemFactory) | ||
{ | ||
if (cache == null) throw new ArgumentNullException(nameof(cache)); | ||
|
||
return cache.GetOrAddAsync(key, addItemFactory, cache.DefaultCachePolicy.BuildOptions()); | ||
} | ||
|
||
|
||
public static Task<T> GetOrAddAsync<T>(this IAppCache cache, string key, Func<Task<T>> addItemFactory, | ||
DateTimeOffset expires) | ||
{ | ||
if (cache == null) throw new ArgumentNullException(nameof(cache)); | ||
|
||
return cache.GetOrAddAsync(key, addItemFactory, new MemoryCacheEntryOptions {AbsoluteExpiration = expires}); | ||
} | ||
|
||
public static Task<T> GetOrAddAsync<T>(this IAppCache cache, string key, Func<Task<T>> addItemFactory, | ||
TimeSpan slidingExpiration) | ||
{ | ||
if (cache == null) throw new ArgumentNullException(nameof(cache)); | ||
|
||
return cache.GetOrAddAsync(key, addItemFactory, | ||
new MemoryCacheEntryOptions {SlidingExpiration = slidingExpiration}); | ||
} | ||
|
||
public static Task<T> GetOrAddAsync<T>(this IAppCache cache, string key, Func<Task<T>> addItemFactory, | ||
MemoryCacheEntryOptions policy) | ||
{ | ||
if (cache == null) throw new ArgumentNullException(nameof(cache)); | ||
|
||
return cache.GetOrAddAsync(key, entry => | ||
{ | ||
entry.SetOptions(policy); | ||
return addItemFactory(); | ||
}); | ||
} | ||
} | ||
} |