Skip to content

Infrastructure ‐ InMemoryCacheRepository

Alessio Di Salvo edited this page Oct 30, 2026 · 3 revisions

InMemoryCacheRepository (ModularNet.Infrastructure.Implementations)

Implements IInMemoryCacheRepository as a thread-safe (lock), in-process memory cache backed by List<InMemoryCacheItem>. Registered as a Singleton in InfrastructureServiceRegistration.cs and consumed by CacheManager.

Dependencies: ILogger<InMemoryCacheRepository>, IConfiguration

Methods

  • Task SaveToInMemoryCache<T>(string item, T value, int cacheExpirationSeconds): Removes expired items, replaces any existing entry for item, and adds a new InMemoryCacheItem expiring after cacheExpirationSeconds.
  • Task<T?> GetFromInMemoryCache<T>(string item): Removes expired items and returns the cached value cast to T?, or default(T) if not found.
  • Task RemoveFromInMemoryCache(string item): Removes all entries matching key item.
  • Task RemoveExpiredItemsFromInMemoryCache(): Removes all items where ExpirationDate <= DateTime.UtcNow.

Clone this wiki locally