Various updates.

This commit is contained in:
2026-01-25 17:17:31 -05:00
parent f459e0e6e6
commit e1338563ed
15 changed files with 307 additions and 32 deletions

View File

@@ -1,4 +1,5 @@
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options;
namespace Harmonia.Core.Caching;
@@ -27,10 +28,16 @@ public abstract class MemoryCache<TKey, TValue> : Cache<TKey, TValue> where TKey
var cacheEntryOptions = new MemoryCacheEntryOptions()
.SetSize(entrySize)
.SetSlidingExpiration(SlidingExpiration);
.SetSlidingExpiration(SlidingExpiration)
.RegisterPostEvictionCallback(PostEvictionCallback);
_memoryCache.Set(key, entry, cacheEntryOptions);
}
protected virtual void PostEvictionCallback(object? cacheKey, object? cacheValue, EvictionReason evictionReason, object? state)
{
}
protected abstract long GetEntrySize(TValue entry);
}