34 lines
1004 B
C#
34 lines
1004 B
C#
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Moonlight.Api.Configuration;
|
|
|
|
namespace Moonlight.Api.Startup;
|
|
|
|
public partial class Startup
|
|
{
|
|
private static void AddCache(WebApplicationBuilder builder)
|
|
{
|
|
// Load cache options
|
|
var cacheOptions = new CacheOptions();
|
|
builder.Configuration.GetSection("Moonlight:Cache").Bind(cacheOptions);
|
|
|
|
builder.Services.AddMemoryCache();
|
|
builder.Services.AddHybridCache();
|
|
|
|
if (!cacheOptions.EnableLayer2)
|
|
return;
|
|
|
|
var redisOptions = new RedisOptions();
|
|
builder.Configuration.GetSection("Moonlight:Redis").Bind(redisOptions);
|
|
|
|
if(!redisOptions.Enable)
|
|
return;
|
|
|
|
builder.Services.AddStackExchangeRedisCache(options =>
|
|
{
|
|
options.Configuration = redisOptions.ConnectionString;
|
|
options.InstanceName = "Moonlight:";
|
|
});
|
|
}
|
|
} |