2013-03-06 91 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操作上返回缓存数据,但是您的系统可以像访问其他数据存储一样访问缓存数据。再次,你只需要识别缓存,我没有最新的一组数据。