Add project files.

This commit is contained in:
2025-08-26 09:20:13 -04:00
parent 6c6a149821
commit d2201d6f9b
118 changed files with 1924 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
using JSMR.Application.Common.Caching;
using Microsoft.Extensions.Caching.Memory;
namespace JSMR.Infrastructure.Caching;
public class MemoryCacheAdapter(IMemoryCache memoryCache) : ICache
{
public ValueTask<T?> GetAsync<T>(string key, CancellationToken cancellationToken = default)
{
memoryCache.TryGetValue(key, out T? value);
return ValueTask.FromResult(value);
}
public ValueTask SetAsync<T>(string key, T value, CacheEntryOptions options, CancellationToken cancellationToken = default)
{
MemoryCacheEntryOptions memoryCacheOptions = new();
if (options.AbsoluteExpirationRelativeToNow != null)
memoryCacheOptions.SetAbsoluteExpiration(options.AbsoluteExpirationRelativeToNow.Value);
if (options.AbsoluteExpiration != null)
memoryCacheOptions.SetAbsoluteExpiration(options.AbsoluteExpiration.Value);
if (options.SlidingExpiration != null)
memoryCacheOptions.SetSlidingExpiration(options.SlidingExpiration.Value);
memoryCache.Set(key, value, memoryCacheOptions);
return ValueTask.CompletedTask;
}
}