From ddb48e07ffaf7d561fcaef7e8d5db8178540697d Mon Sep 17 00:00:00 2001 From: JohnL404 Date: Wed, 27 Mar 2019 09:36:01 -0500 Subject: [PATCH] Renamed AppCacheExtenions to AppCacheExtensions. (#65) --- ...acheExtenions.cs => AppCacheExtensions.cs} | 198 +++++++++--------- 1 file changed, 99 insertions(+), 99 deletions(-) rename LazyCache/{AppCacheExtenions.cs => AppCacheExtensions.cs} (96%) diff --git a/LazyCache/AppCacheExtenions.cs b/LazyCache/AppCacheExtensions.cs similarity index 96% rename from LazyCache/AppCacheExtenions.cs rename to LazyCache/AppCacheExtensions.cs index 3823a87..7ea169b 100644 --- a/LazyCache/AppCacheExtenions.cs +++ b/LazyCache/AppCacheExtensions.cs @@ -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(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(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(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(this IAppCache cache, string key, Func addItemFactory) - { - if (cache == null) throw new ArgumentNullException(nameof(cache)); - - return cache.GetOrAdd(key, addItemFactory, cache.DefaultCachePolicy.BuildOptions()); - } - - public static T GetOrAdd(this IAppCache cache, string key, Func addItemFactory, DateTimeOffset expires) - { - if (cache == null) throw new ArgumentNullException(nameof(cache)); - - return cache.GetOrAdd(key, addItemFactory, new MemoryCacheEntryOptions {AbsoluteExpiration = expires}); - } - - public static T GetOrAdd(this IAppCache cache, string key, Func addItemFactory, - TimeSpan slidingExpiration) - { - return cache.GetOrAdd(key, addItemFactory, - new MemoryCacheEntryOptions {SlidingExpiration = slidingExpiration}); - } - - public static T GetOrAdd(this IAppCache cache, string key, Func addItemFactory, - MemoryCacheEntryOptions policy) - { - if (cache == null) throw new ArgumentNullException(nameof(cache)); - - return cache.GetOrAdd(key, entry => - { - entry.SetOptions(policy); - return addItemFactory(); - }); - } - - public static Task GetOrAddAsync(this IAppCache cache, string key, Func> addItemFactory) - { - if (cache == null) throw new ArgumentNullException(nameof(cache)); - - return cache.GetOrAddAsync(key, addItemFactory, cache.DefaultCachePolicy.BuildOptions()); - } - - - public static Task GetOrAddAsync(this IAppCache cache, string key, Func> addItemFactory, - DateTimeOffset expires) - { - if (cache == null) throw new ArgumentNullException(nameof(cache)); - - return cache.GetOrAddAsync(key, addItemFactory, new MemoryCacheEntryOptions {AbsoluteExpiration = expires}); - } - - public static Task GetOrAddAsync(this IAppCache cache, string key, Func> addItemFactory, - TimeSpan slidingExpiration) - { - if (cache == null) throw new ArgumentNullException(nameof(cache)); - - return cache.GetOrAddAsync(key, addItemFactory, - new MemoryCacheEntryOptions {SlidingExpiration = slidingExpiration}); - } - - public static Task GetOrAddAsync(this IAppCache cache, string key, Func> 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(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(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(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(this IAppCache cache, string key, Func addItemFactory) + { + if (cache == null) throw new ArgumentNullException(nameof(cache)); + + return cache.GetOrAdd(key, addItemFactory, cache.DefaultCachePolicy.BuildOptions()); + } + + public static T GetOrAdd(this IAppCache cache, string key, Func addItemFactory, DateTimeOffset expires) + { + if (cache == null) throw new ArgumentNullException(nameof(cache)); + + return cache.GetOrAdd(key, addItemFactory, new MemoryCacheEntryOptions {AbsoluteExpiration = expires}); + } + + public static T GetOrAdd(this IAppCache cache, string key, Func addItemFactory, + TimeSpan slidingExpiration) + { + return cache.GetOrAdd(key, addItemFactory, + new MemoryCacheEntryOptions {SlidingExpiration = slidingExpiration}); + } + + public static T GetOrAdd(this IAppCache cache, string key, Func addItemFactory, + MemoryCacheEntryOptions policy) + { + if (cache == null) throw new ArgumentNullException(nameof(cache)); + + return cache.GetOrAdd(key, entry => + { + entry.SetOptions(policy); + return addItemFactory(); + }); + } + + public static Task GetOrAddAsync(this IAppCache cache, string key, Func> addItemFactory) + { + if (cache == null) throw new ArgumentNullException(nameof(cache)); + + return cache.GetOrAddAsync(key, addItemFactory, cache.DefaultCachePolicy.BuildOptions()); + } + + + public static Task GetOrAddAsync(this IAppCache cache, string key, Func> addItemFactory, + DateTimeOffset expires) + { + if (cache == null) throw new ArgumentNullException(nameof(cache)); + + return cache.GetOrAddAsync(key, addItemFactory, new MemoryCacheEntryOptions {AbsoluteExpiration = expires}); + } + + public static Task GetOrAddAsync(this IAppCache cache, string key, Func> addItemFactory, + TimeSpan slidingExpiration) + { + if (cache == null) throw new ArgumentNullException(nameof(cache)); + + return cache.GetOrAddAsync(key, addItemFactory, + new MemoryCacheEntryOptions {SlidingExpiration = slidingExpiration}); + } + + public static Task GetOrAddAsync(this IAppCache cache, string key, Func> addItemFactory, + MemoryCacheEntryOptions policy) + { + if (cache == null) throw new ArgumentNullException(nameof(cache)); + + return cache.GetOrAddAsync(key, entry => + { + entry.SetOptions(policy); + return addItemFactory(); + }); + } + } } \ No newline at end of file