2025-06-06 14:57:20 +08:00

22 lines
647 B
C#

using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.DependencyInjection;
using System;
namespace YD_WeChatApplet.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;
});
}
}
}