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 操作にのみ適用し、UPDATE された場合は無効にしますか。

ServiceStack では、キャッシュを手動でクリア/無効化するか、時間ベースの有効期限を設定できます。キャッシュを手動でクリアする場合は、DELETES と UPDATES で行うことをお勧めします。キャッシュの管理/無効化の方法は自由に選択できます。キャッシュに古いデータが残るのを避けたいだけです。「キャッシュを適用」する限り、GET 操作でキャッシュされたデータを返しますが、システムは他のデータ ストアと同じようにキャッシュされたデータにアクセスできます。繰り返しますが、キャッシュに最新のデータ セットがないことを認識する必要があります。

于 2013-03-06T17:09:29.337 に答える