22 lines
641 B
C#
Raw Normal View History

2025-01-13 21:06:59 +08:00
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.DependencyInjection;
using System;
namespace YD_XinWei.Commons.MemoryCaches
{
public static class MemoryCacheSetup
{
public static void AddMemoryCacheSetup(this IServiceCollection services)
{
if (services == null) throw new ArgumentNullException(nameof(services));
services.AddScoped<ICaching, MemoryCaching>();
services.AddScoped<IMemoryCache>(factory =>
{
var cache = new MemoryCache(new MemoryCacheOptions());
return cache;
});
}
}
}