-
-
Save dcomartin/fc3654f90f498e1f4288980630f5a59d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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