2014年8月16日 星期六

2 Cache Pattenrs

Cache Pattern

  a. Load All Data in Cache ( In order to save the over amount access for DB)
  b. Load Data On Demand in Cache ( In order to save the over amount access for DB)
 
Key

  Target Cache
  Source DB Record
 
Solution

  a.
 
  // POCO
  public class TRecord
  {
     field definition { get; set;}
  }
  public class CacheAllMgr
  {
     private static Dictionay<TKey, TRecord> _cacheRecord = new Dictionay<TKey, TRecord>();
     private CacheAllMgr();  // Singleton
     publc Dictionay<TKey, TRecord> GetAll()
     {
        if (_cacheRecord.Count == 0)
        {
           using (var context = new EF())
           {
          for(var item in context.DB)
          {
              _cacheRecord.Add(TKey, new TRecord { ... });
          }
           }
        }
        return _cacheRecord;
     }    
  }
 
  b.
  public class CacheOnDemandMgr
  {
      private static Dictionay<TKey, TRecord> _cacheRecord = new Dictionay<TKey, TRecord>();
      public TRecord FindRecordByKey(T key)
      {
         TRecord result = null
         if (_cacheRecord.Keys.Contains(key)
         {
           return _cacheRecord[key];
         }
         else
         {
           using (var context = new EF())
           {
               var records = context.DB.Where(it=>it.key == key);
               if (records.Count() > 0)
               {
                 _cacheRecord.Add(key, new TRecord { field1 = records[0].field1 ... }); // load data from db into cache
                 result = _cacheRecord[key];
               }
           }
         }
         return result;
      }    
  }
 
 

2014年8月4日 星期一

VS 2012 advance short cut keys

Mark comments or uncomment your code
Ctrl+E, Ctrl+C (Comment)
or
Ctrl+K C

Ctrl+E, Ctrl+U (UnComment)
or
Ctrl+K U

可以按一下 [編輯]/[IntelliSense]/[參數資訊],輸入 CTRL+SHIFT+空格鍵,或按一下編輯器工具列上的 [參數資訊] 按鈕,手動叫用參數資訊。

可以按一下 [編輯/IntelliSense/快速資訊],輸入或按 CTRL+I 手動叫用快速諮詢 [快速諮詢] 按鈕在編輯器工具列。

可以按一下 [編輯]/[IntelliSense]/[自動完成文字],輸入 CTRL+空格鍵,或按一下編輯器工具列上的 [自動完成文字] 按鈕,叫用 [自動完成文字]。

Debug and step over
F10
Debug and go to cursor
Ctrl + F10
Debug and step trace
F11
Debug and exit current loop
Shift + F11


http://www.veodin.com/keyrocket/visual-studio-2012-shortcuts/