Asp.net mvc cache service update data logic

2013 年 5 月 13 日3300

I am using asp.net mvc developing a simple project. I created a service interface named IProductService to get products.

I created a real database service and a cache service.

public interface IProductService{



IEnumerable<Product> Get();



}







public class ProductService : IProductService{



public IEnumerable<Product> Get(){



//get data from database...



}



}



public class CachedProductService:IProductService{







IProductService service;







public CachedProductService(IProductService service){



this.service=service;



}







public IEnumerable<Product> Get(){



var data = (get from cache data);



if(data=null){



data = (add data to cache and return)



}



return data;



}



}

Have you ever worked a project like this? My question is, when do you update the cache data. For example anyone inserted new data, or a trigger like logic? If I insert a new record to database new data does not come to main page if I not update the cache data.

0 0