I\'ve done the following in my regular MVC controller:
public ActionResult GetCourses()
{
List courses = new List();
if (this.H
You can set the cache from Web API controller like this.
var context = HttpContext.Current;
if (context != null)
{
if (context.Cache["courses"] == null)
{
context.Cache["courses"] = _db.Courses.ToList();
}
}
For the sake of simplicity, I'm not using any locking here. If your application has high concurrency, it is better to implement a lock while setting the cache.
Also, in order for the cache set by We API to be read by MVC, your Web API and MVC controllers must be part of the same application. Just stating the obvious.