简体   繁体   中英

Mvc 4 cache database for ecommerce project

I have a MVC4 project for ecommerce about to finish. I use sqldependecy with outputcache. But what is the best way of this? Product detail page ? category page which have products list ? filter page ? bla bla

Could you help me about caching? (i use sql server with linq to sql in my project) Example;

[OutputCache(Duration = Int32.MaxValue, SqlDependency = "Demo:product")]

public ActionResult getproducts(int id, int lastid,string filter) {

i get the data from sql with params.

}

is it right?or should cache the query data bla bla? lastid used for paging. filter parameters for filter data. id means categoryid

Let's start from the beginning: I assume you want to optimize your webshop and that's why you need some caching mechanisms. You have chosen to use OutputCache probably because it is easy to use and it is available out of the box. As you probably know OutputCache caches the responses from the server so it is not directly connected with caching sql queries or with data in general. Therefore I firstly recommend to think what type of cache you really need - output cache (located in System.Web.Configuration.OutputCacheSection), data cache (located in System.Web.Caching.Cache) or both?

Let's assume that you have chosen OutputCache. You need to make sure that everything that can change the response from server should be send as a cache parameter. So in case of a Product Page this will probably be at least a ProductId, in case of CategoryPage (ProductListPage) this will be probably CategoryId, PageId, PageSize, some sorting parameters, filter parameters (if you use filtering) etc.

The more parameters you need to take into account the more time-consuming it will be to cache all possible parameters combinations. As an example I would use OutputCaching for Product Page but I would consider using this for CategoryPage (ProductListPage) especially in case of using filters, paging, sorting, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM