Created
December 7, 2019 05:14
-
-
Save pkellner/f9335a2d3ddd9f610ee818fd3faa86a9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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