1
0
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:
Kyle Spearrin 2017-10-09 14:54:32 -04:00
parent 051d64a460
commit 02c4bb3037
4 changed files with 22 additions and 7 deletions

View File

@ -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("")]

View File

@ -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; }
} }
} }

View File

@ -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();
} }

View File

@ -13,7 +13,8 @@
} }
}, },
"iconsSettings": { "iconsSettings": {
"BestIconBaseUrl": "https://icons.better-idea.org", "bestIconBaseUrl": "https://icons.better-idea.org",
"CacheHours": 24 "cacheHours": 24,
"cacheSizeLimit": null
} }
} }