Skip to content

Instantly share code, notes, and snippets.

Created May 11, 2023 18:03
What would you like to do?
public class CacheRepository<T> : IRepository<T>
private readonly IMemoryCache _cache;
private readonly EfRepository<T> _repository;
public CacheRepository(IMemoryCache cache, EfRepository<T> repository)
_cache = cache;
_repository = repository;
public async Task<List<T>> List(ISpecification<T> specification, CancellationToken cancellationToken = default)
return await _memoryCache.GetOrCreateAsync(specification.CacheKey, async entry =>
entry.SlidingExpiration = TimeSpan.FromMinutes(15);
return await _repository.List(specification, cancellationToken);
// The rest of the implementation....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment