日本好好热aⅴ|国产99视频精品免费观看|日本成人aV在线|久热香蕉国产在线

  • <cite id="ikgdy"><table id="ikgdy"></table></cite>
    1. 西西軟件園多重安全檢測下載網(wǎng)站、值得信賴的軟件下載站!
      軟件
      軟件
      文章
      搜索

      首頁編程開發(fā)其它知識 → 緩存的加載策略--Proactive 和Reactive

      緩存的加載策略--Proactive 和Reactive

      相關(guān)軟件相關(guān)文章發(fā)表評論 來源:本站整理時間:2010/12/28 0:55:23字體大小:A-A+

      作者:佚名點擊:33次評論:3次標簽: Proactive Reactive 加載策略

      • 類型:加密解密大。2.7M語言:中文 評分:7.6
      • 標簽:
      立即下載
      proactive的策略就是一開始就將所有backing store中的數(shù)據(jù)加載到進程內(nèi)存中,這樣做的好處是在數(shù)據(jù)量相對不大的時候會顯得很有效率,無需頻繁的訪問backing store調(diào)出數(shù)據(jù),并且也不用再代碼中判斷緩存中是否緩存有數(shù)據(jù),是否要從backing store中加載。

      reactive策略是“按需加載”,在程序初始化階段僅加載必要的數(shù)據(jù)到內(nèi)存緩存起來,其余數(shù)據(jù)只有在需要時才從數(shù)據(jù)庫中調(diào)出再緩存。這種策略比較保守,缺點是在數(shù)據(jù)量比較大且頻繁訪問之初由于要多次頻繁的向backing store獲取數(shù)據(jù),但通常我們使用這種的就是這種策略。

      下面是兩種方案的示例代碼比較:

      proactive的方式
      public List<Product> GetProductList()
      {
      return Respository<Product>.ResolveAll();
      }
      public void LoadAllProducts(ICacheManager cache)
      {
      List<Product>list = GetProductList();

      for (int i = 0; i < list.Count; i++)
      {
      Product newProduct = list[i];
      cache.Add(newProduct.ProductID, newProduct);
      }
      }


      reactive的方式
      public List<Product> GetProductList()
      {
      return Respository<Product>.ResolveAll();
      }
      public Product ReadProductByID(ICacheManager cache, string productID)
      {
      Product newProduct = (Product)cache.GetData(productID);

      // Does our cache already have the requested object?
      if (newProduct == null)
      {
      // The requested object is not cached, so retrieve it from
      // the data provider and cache it for further requests.
      newProduct = this.dataProvider.GetProductByID(productID);

      if (newProduct != null)
      {
      cache.Add(newProductID, newProduct);
      }
      }
      return newProduct;
      }

      緩存隔離:Partitioned Caches

      一個caching block中CacheManager不能被多個進程或是一個進程的不同應(yīng)用程序域所共享。但多個進程或是同一進程的多個應(yīng)用程序域共享一個緩存的需求還是很必要的。關(guān)鍵在于如何設(shè)計合理。

      三種情形:

      A.Partitioned Caches:每個進程/同一進程的不同應(yīng)用程序域使用不同的backing storage。這是最簡單的情況,也不需要我們進行額外的同步處理。每個進程/應(yīng)用程序域你用你的我用我的大家互不干涉。但這無法是多個進程共享一個backing storage。比如isolatedstorage作為backing storage,如果是不同用戶會自動分配不同的隔離存儲空間,對于同一用戶的話只需將partition配置為不同值即可。



      B.Shared Partition:n個進程中只有1個進程能夠修改backing storage,所有進程都能夠讀取backing storage的數(shù)據(jù)。這種情況是最理想的,但需要邏輯上的支持。

      C.Single Writer:n個進程都能夠修改和讀取backing storage,這是最糟糕的情況,很容易產(chǎn)生錯亂,會導致不同步的現(xiàn)象。

        相關(guān)評論

        閱讀本文后您有什么感想? 已有人給出評價!

        • 8 喜歡喜歡
        • 3 頂
        • 1 難過難過
        • 5 囧
        • 3 圍觀圍觀
        • 2 無聊無聊

        熱門評論

        最新評論

        發(fā)表評論 查看所有評論(3)

        昵稱:
        表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
        字數(shù): 0/500 (您的評論需要經(jīng)過審核才能顯示)