I searched for Caching in my web api, where I can use the output of one api method (which changes once every 12 hours) for sequenceesnt calls, and then I found this solution in SO, but I find it difficult to understand and use the code below
private IEnumerable<TEntity> GetFromCache<TEntity>(string key, Func<IEnumerable<TEntity>> valueFactory) where TEntity : class { ObjectCache cache = MemoryCache.Default; var newValue = new Lazy<IEnumerable<TEntity>>(valueFactory); CacheItemPolicy policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(30) };
I'm not sure how to call and use this method in the context below? I have a get method
public IEnumerable<Employee> Get() { return repository.GetEmployees().OrderBy(c => c.EmpId); }
and I want to cache Get output and use it in my other GetEmployeeById () or Search () methods
public Movie GetEmployeeById(int EmpId) {
c # asp.net-mvc asp.net-web-api memorycache asp.net-web-api2
F11 Oct 27 '14 at 4:10 2014-10-27 04:10
source share