Skip to content

Instantly share code, notes, and snippets.

@pkellner
Created December 7, 2019 05:14
Show Gist options
  • Save pkellner/f9335a2d3ddd9f610ee818fd3faa86a9 to your computer and use it in GitHub Desktop.
Save pkellner/f9335a2d3ddd9f610ee818fd3faa86a9 to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using System.Threading.Tasks;
using ClassLib.CacheExtension;
using EFLibSvcc.Models;
using Microsoft.Extensions.Caching.Memory;
namespace CarvedRock.Api.Repositories
{
public class RoomRepositoryCached
{
private readonly IMemoryCache _cache;
private readonly RoomRepository _roomRepository;
private readonly int timeOut = 60;
public RoomRepositoryCached(RoomRepository roomRepository, IMemoryCache cache)
{
_roomRepository = roomRepository;
_cache = cache;
}
public async Task<IEnumerable<LectureRooms>> GetAll()
{
var t = new TCache<IEnumerable<LectureRooms>>(_cache);
return
await t.Get(
"RoomRepositoryCached-GetAll",
() => _roomRepository.GetAll(), timeOut);
}
public async Task<IEnumerable<LectureRooms>> GetByCodeCampYear(string year)
{
var t = new TCache<IEnumerable<LectureRooms>>(_cache);
return
await t.Get(
"CodeCampYearRepositoryCached-GetOne-" + year,
() => _roomRepository.GetByCodeCampYear(year));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment