set the cache limits from settings

This commit is contained in:
Nicolas Constant 2022-02-03 19:01:21 -05:00
parent 25ba19bc4f
commit 1536880c73
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
4 changed files with 14 additions and 7 deletions

View File

@ -50,6 +50,7 @@ If both whitelisting and blacklisting are set, only the whitelisting will be act
* `Instance:SensitiveTwitterAccounts` (default: null) mark all media from given accounts as sensitive by default, separated by `;`.
* `Instance:FailingTwitterUserCleanUpThreshold` (default: 700) set the max allowed errors (due to a banned/deleted/private account) from a Twitter Account retrieval before auto-removal. (by default an account is called every 15 mins)
* `Instance:FailingFollowerCleanUpThreshold` (default: 30000) set the max allowed errors from a Follower (Fediverse) Account before auto-removal. (often due to account suppression, instance issues, etc)
* `Instance:UserCacheCapacity` (default: 10000) set the caching limit of the Twitter User retrieval. Must be higher than the number of synchronized accounts on the instance.
# Docker Compose full example

View File

@ -14,5 +14,7 @@
public int FailingTwitterUserCleanUpThreshold { get; set; }
public int FailingFollowerCleanUpThreshold { get; set; } = -1;
public int UserCacheCapacity { get; set; }
}
}

View File

@ -1,4 +1,5 @@
using System;
using BirdsiteLive.Common.Settings;
using BirdsiteLive.Twitter.Models;
using Microsoft.Extensions.Caching.Memory;
@ -13,11 +14,8 @@ namespace BirdsiteLive.Twitter
{
private readonly ITwitterUserService _twitterService;
private MemoryCache _userCache = new MemoryCache(new MemoryCacheOptions()
{
SizeLimit = 5000
});
private MemoryCacheEntryOptions _cacheEntryOptions = new MemoryCacheEntryOptions()
private readonly MemoryCache _userCache;
private readonly MemoryCacheEntryOptions _cacheEntryOptions = new MemoryCacheEntryOptions()
.SetSize(1)//Size amount
//Priority on removing when reaching size limit (memory pressure)
.SetPriority(CacheItemPriority.High)
@ -27,9 +25,14 @@ namespace BirdsiteLive.Twitter
.SetAbsoluteExpiration(TimeSpan.FromDays(7));
#region Ctor
public CachedTwitterUserService(ITwitterUserService twitterService)
public CachedTwitterUserService(ITwitterUserService twitterService, InstanceSettings settings)
{
_twitterService = twitterService;
_userCache = new MemoryCache(new MemoryCacheOptions()
{
SizeLimit = settings.UserCacheCapacity
});
}
#endregion

View File

@ -24,7 +24,8 @@
"UnlistedTwitterAccounts": null,
"SensitiveTwitterAccounts": null,
"FailingTwitterUserCleanUpThreshold": 700,
"FailingFollowerCleanUpThreshold": 30000
"FailingFollowerCleanUpThreshold": 30000,
"UserCacheCapacity": 10000
},
"Db": {
"Type": "postgres",