pictureServer/PictureFilesApi/Common/CacheHelper.cs

27 lines
657 B
C#
Raw Permalink Normal View History

2026-03-10 09:04:34 +08:00
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);
}
}
}