我有4類如下:如何緩存對象並從內存中讀取,如果它存在而不是數據庫?
public class Section
{
public int SectionId { get; set; }
public string Name { get; set; }
public string Title { get; set; }
public string MetaTag { get; set; }
public string MetaDescription { get; set; }
public string UrlSafe { get; set; }
public string Header { get; set; }
public string ImageName { get; set; }
}
public interface ISectionRepository
{
List<Section> GetAllSections();
}
public class SectionRepository : ISectionRepository
{
Context context = new Context();
public List<Section> GetAllSections()
{
return context.Sections.ToList();
}
}
public class SectionApplication
{
SectionRepository sectionRepo = new SectionRepository();
public List<Section> GetAllSections()
{
return sectionRepo.GetAllSections();
}
}
,在我的控制,我有:
public class SectionController : Controller
{
SectionApplication sectionApp = new SectionApplication();
public ActionResult Index()
{
return View(sectionApp.GetAllSections());
}
}
現在,我想這樣做: 我想chache內存部分在特定時間爲了從緩存中讀取部分(如果存在),否則從數據庫讀取它。
哪個組件與DB的作品? – sll 2013-02-21 10:16:49
看看。 http://stackoverflow.com/questions/1276569/caching-in-c-net – Jharis 2013-02-21 10:16:58