27 lines
657 B
C#
27 lines
657 B
C#
|
|
using Microsoft.Extensions.Caching.Memory;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
|
|||
|
|
namespace LongHuParkApi.Common
|
|||
|
|
{
|
|||
|
|
public static class CacheHelper
|
|||
|
|
{
|
|||
|
|
private static MemoryCache cache = new MemoryCache(new MemoryCacheOptions());
|
|||
|
|
|
|||
|
|
public static void SetCache<T>(string key, T value, TimeSpan timeSpan)
|
|||
|
|
{
|
|||
|
|
cache.Set(key, value, new MemoryCacheEntryOptions
|
|||
|
|
{
|
|||
|
|
SlidingExpiration = timeSpan
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static T GetCache<T>(string key)
|
|||
|
|
{
|
|||
|
|
return cache.Get<T>(key);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|