2010-04-12 77 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); 

    } 

回答