In an ASP.NET Core MVC app I'm using IMemoryCache
in ConfigureServices()
:
services.AddMemoryCache();
In a controller, I originally had this code:
// List<> of POCOs:
var myLines = await _context.MyEntity.Where(somecondition).ToListAsync();
and I've changed it to:
// List<> of POCOs:
var myLines = await
_cache.GetOrCreateAsync("mykey",async entry => {
return
await _context.MyEntity.Where(somecondition).ToListAsync();
});
This works well.
But I'm wondering if it is a bad practice anyway or not.
Is it a problem caching attached POCOs?