1

I am new to caching and trying to understand how it works in general. Below is code snippet from ServiceStack website.

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 });
        }
    });
}

My doubts are:

  1. I've read that cached data is stored in RAM on same/distributed server. So, how much data can it handle, suppose in first method if customers count is more than 1 million, doesn't it occupy too much memory.

  2. In general case, do we apply caching only for GET operations and invalidate if it gets UPDATE'd.

  3. Please suggest any tool to check memory consumption of caching.

4

1 回答 1

2

我想你可以在这里找到问题的答案 - https://github.com/ServiceStack/ServiceStack/wiki/Caching

我读过缓存数据存储在同一/分布式服务器上的 RAM 中......

有几种方法可以“持久化”缓存数据。同样,请参见此处 - https://github.com/ServiceStack/ServiceStack/wiki/Caching。'InMemory' 是您似乎质疑的选项。其他选项对 RAM 的影响不同。

在一般情况下,我们是否仅对 GET 操作应用缓存,如果它被更新则无效。

在 ServiceStack 中,您可以手动清除/使缓存无效或设置基于时间的过期时间。如果您手动清除缓存,我建议您在 DELETES 和 UPDATES 上这样做。您可以自由选择如何管理/使缓存无效。您只是想避免缓存中有陈旧的数据。至于“应用缓存”,您将在 GET 操作中返回缓存数据,但您的系统可以像访问任何其他数据存储一样访问缓存数据。同样,您只需要识别缓存我没有最新的数据集。

于 2013-03-06T17:09:29.337 回答