Implemented hybrid cache for user sessions, api keys and database provided settings. Cleaned up startup and adjusted caching option models for features
This commit is contained in:
34
Moonlight.Api/Startup/Startup.Cache.cs
Normal file
34
Moonlight.Api/Startup/Startup.Cache.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
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:";
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user