2010-04-12 76 views
0

即時新的城堡活動記錄模式和我試圖讓我的腦袋周圍如何有效地使用緩存。 所以即時嘗試做(或想要做的)是調用GetAll時,發現如果我之前調用它並檢查緩存,否則加載它,但我也想傳遞一個布爾參數,將強制緩存清除和重新查詢數據庫。城堡活動記錄 - 使用緩存

所以我只是尋找最後的位。 感謝

 public static List<Model.Resource> GetAll(bool forceReload) 
    { 
     List<Model.Resource> resources = new List<Model.Resource>(); 


     //Request to force reload 
     if (forceReload) 
     { 
      //need to specify to force a reload (how?) 
      XmlConfigurationSource source = new XmlConfigurationSource("appconfig.xml"); 
      ActiveRecordStarter.Initialize(source, typeof(Model.Resource)); 
      resources = Model.Resource.FindAll().ToList(); 
     } 
     else 
     { 
      //Check the cache somehow and return the cache? 
     } 

     return resources; 
    } 


    public static List<Model.Resource> GetAll() 
    { 

     return GetAll(false); 

    } 

回答