How cache works in ServiceStack web services

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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>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 });
}
});
}
</code>
<code>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 }); } }); } </code>
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:

  1. I’ve read that cached data is stored on same/distributed server RAM. 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. Ingeneral, 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.

Please read ServiceStack’s wiki page on Caching.

What memory gets used is entirely determined by the Caching provider used, e.g. if you use a distributed cache like Redis or Memcached the memory of the process of that daemon/service will grow to retain the cached data. If you use ServiceStack’s MemoryCachedClient (the Default) then caches are just kept in memory, i.e. in the ASP.NET w3wp.exe process.

How big the cache is, is directly effected by what is cached.

Your caching strategy you choose is independent of the caching providers, the example provided uses a caching pattern that lazily creates the cache when fetched and invalidates it when changed.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật