The next generation of the Teknik Services. Written in ASP.NET.
https://www.teknik.io/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.0 KiB
33 lines
1.0 KiB
using System; |
|
using System.Collections.Generic; |
|
using System.Text; |
|
using Microsoft.Extensions.Caching.Memory; |
|
|
|
namespace Teknik.Utilities |
|
{ |
|
public static class MemoryCacheHelper |
|
{ |
|
public static bool GetCacheValue<T>(this IMemoryCache cache, string key, out T value) |
|
{ |
|
return cache.TryGetValue(key, out value); |
|
} |
|
|
|
public static bool GetCacheValue(this IMemoryCache cache, string key, out object value) |
|
{ |
|
return cache.TryGetValue(key, out value); |
|
} |
|
|
|
public static void AddToCache(this IMemoryCache cache, string key, object value, TimeSpan expiration) |
|
{ |
|
var cacheOptions = new MemoryCacheEntryOptions() |
|
.SetAbsoluteExpiration(expiration); |
|
|
|
cache.AddToCache(key, value, cacheOptions); |
|
} |
|
|
|
public static void AddToCache(this IMemoryCache cache, string key, object value, MemoryCacheEntryOptions options) |
|
{ |
|
cache.Set(key, value, options); |
|
} |
|
} |
|
}
|
|
|