2013-03-06 90 views
1

我是新來的緩存,並試圖瞭解它是如何工作的一般。以下是來自ServiceStack網站的代碼片段。ServiceStack網絡服務緩存

public object Get(CachedCustomers request) 
{ 
    //Manually create the Unified Resource Name "urn:customers". 
    return base.RequestContext.ToOptimizedResultUsingCache(base.Cache, "urn:customers",() => 
    { 
     //Resolve the service in order to get the customers. 
     using (var service = this.ResolveService<CustomersService>()) 
       return service.Get(new Customers()); 
    }); 
} 

public object Get(CachedCustomerDetails request) 
{ 
    //Create the Unified Resource Name "urn:customerdetails:{id}". 
    var cacheKey = UrnId.Create<CustomerDetails>(request.Id); 
    return base.RequestContext.ToOptimizedResultUsingCache(base.Cache, cacheKey,() => 
    { 
     using (var service = this.ResolveService<CustomerDetailsService>()) 
     { 
      return service.Get(new CustomerDetails { Id = request.Id }); 
     } 
    }); 
} 

我的疑惑是:

  1. 我讀過,緩存的數據存儲在相同/分佈式服務器上RAM。那麼,它能處理多少數據,假設第一種方法如果客戶數量超過100萬,是不是佔用太多內存。

  2. 在一般情況下,我們是否只對GET操作應用緩存,如果得到UPDATE'd就無效。

  3. 請建議任何工具來檢查內存消耗的緩存。

回答

2

我想你可以在這裏找到問題的答案 - https://github.com/ServiceStack/ServiceStack/wiki/Caching

我讀過,緩存的數據存儲在相同/分佈式服務器上的內存...

有有幾種方法可以「堅持」緩存的數據。再次看到這裏 - https://github.com/ServiceStack/ServiceStack/wiki/Caching。 'InMemory'是你似乎在質疑的選項。其他選項對RAM沒有同樣的影響。

在一般情況下,我們是否只對GET操作應用緩存,如果得到UPDATE'd就無效。

在ServiceStack中,您可以手動清除/使緩存無效或具有基於時間的到期。如果您手動清除緩存,我建議在刪除和更新時這樣做。您可以自由選擇如何管理/無效緩存。你只是想避免在你的緩存中陳舊的數據。就'應用緩存'而言,您將在GET操作上返回緩存數據,但是您的系統可以像訪問其他數據存儲一樣訪問緩存數據。再次,你只需要識別緩存,我沒有最新的一組數據。