mirror of
https://github.com/bitwarden/server.git
synced 2025-01-26 22:31:30 +01:00
configurable cache size limit
This commit is contained in:
parent
051d64a460
commit
02c4bb3037
@ -5,7 +5,6 @@ using Bit.Icons.Models;
|
|||||||
using Bit.Icons.Services;
|
using Bit.Icons.Services;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Caching.Memory;
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
|
|
||||||
namespace Bit.Icons.Controllers
|
namespace Bit.Icons.Controllers
|
||||||
{
|
{
|
||||||
@ -20,11 +19,11 @@ namespace Bit.Icons.Controllers
|
|||||||
public IconsController(
|
public IconsController(
|
||||||
IMemoryCache memoryCache,
|
IMemoryCache memoryCache,
|
||||||
IDomainMappingService domainMappingService,
|
IDomainMappingService domainMappingService,
|
||||||
IOptions<IconsSettings> iconsSettingsOptions)
|
IconsSettings iconsSettings)
|
||||||
{
|
{
|
||||||
_memoryCache = memoryCache;
|
_memoryCache = memoryCache;
|
||||||
_domainMappingService = domainMappingService;
|
_domainMappingService = domainMappingService;
|
||||||
_iconsSettings = iconsSettingsOptions.Value;
|
_iconsSettings = iconsSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("")]
|
[HttpGet("")]
|
||||||
|
@ -4,5 +4,6 @@
|
|||||||
{
|
{
|
||||||
public virtual string BestIconBaseUrl { get; set; }
|
public virtual string BestIconBaseUrl { get; set; }
|
||||||
public virtual int CacheHours { get; set; }
|
public virtual int CacheHours { get; set; }
|
||||||
|
public virtual long? CacheSizeLimit { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,24 @@ namespace Bit.Icons
|
|||||||
|
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
|
// Options
|
||||||
services.AddOptions();
|
services.AddOptions();
|
||||||
services.Configure<IconsSettings>(Configuration.GetSection("IconsSettings"));
|
|
||||||
services.AddMemoryCache();
|
// Settings
|
||||||
|
var iconsSettings = new IconsSettings();
|
||||||
|
ConfigurationBinder.Bind(Configuration.GetSection("IconsSettings"), iconsSettings);
|
||||||
|
services.AddSingleton(s => iconsSettings);
|
||||||
|
|
||||||
|
// Cache
|
||||||
|
services.AddMemoryCache(options =>
|
||||||
|
{
|
||||||
|
options.SizeLimit = iconsSettings.CacheSizeLimit;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Services
|
||||||
services.AddSingleton<IDomainMappingService, DomainMappingService>();
|
services.AddSingleton<IDomainMappingService, DomainMappingService>();
|
||||||
|
|
||||||
|
// Mvc
|
||||||
services.AddMvc();
|
services.AddMvc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"iconsSettings": {
|
"iconsSettings": {
|
||||||
"BestIconBaseUrl": "https://icons.better-idea.org",
|
"bestIconBaseUrl": "https://icons.better-idea.org",
|
||||||
"CacheHours": 24
|
"cacheHours": 24,
|
||||||
|
"cacheSizeLimit": null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user