I have an MVC Web application that basically queries a SQL store procedure for a list of products,I have a WCF service layer that is responsible for the database querying, there is a call that gets products by category and return the data to MVC Grid-view. I have managed to cache on the application level by setting outputcache to a duration of 3600, this works fine, however is caches the data only after I make an initial call to each product categories, how can I make it consistent on start-up. Also how do I cache the data in the WCF service layer. Please see my code to see what I have so far. I am fairly new to MVC can you please help.
public class HomeController : Controller
{
[OutputCache(Duration = 3600, Location = OutputCacheLocation.Client, VaryByParam = "none")]
public ActionResult Index()
{
TopProductWCFService.TopProductServiceClient client = new TopProductWCFService.TopProductServiceClient();
List<Top_100_Result> productType = client.GetTopProductsByTypeName();
ViewBag.ProductType = new SelectList(productType.Select(x => x.Product_Type_Name).Distinct().OrderBy(x => x));
return View("Index", productType);
}
[OutputCache(Duration = 3600)]
public ActionResult ProductDescription(string ProductType)
{
TopProductWCFService.TopProductServiceClient client = new TopProductWCFService.TopProductServiceClient();
List<Top_100_Result> productDesctriptionList = client.GetTopProductsByCategory(ProductType).Where(x => x.Product_Type_Name == ProductType).ToList();//new List<Top_100_Result>();
return PartialView("_ProductDescription", productDesctriptionList);
}
}
public class Service1 : ITopProductService
{
//private const string CacheKey = "topProducts";
public List<Top_100_Result> GetTopProductsByTypeName()
{
using (EmbraceEntities ctx = new EmbraceEntities())
{
var productObjects = ctx.Top_100(null);
return new List<Top_100_Result>(productObjects.Distinct());
}
}
public List<Top_100_Result> GetTopProductsByCategory(string productCategory)
{
using (EmbraceEntities ctx = new EmbraceEntities())
{
var productsCategoryList = ctx.Top_100(productCategory);
return new List<Top_100_Result>(productsCategoryList);
}
}
}