-
Notifications
You must be signed in to change notification settings - Fork 271
/
CachedServices.cs
49 lines (40 loc) · 1.37 KB
/
CachedServices.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
namespace ServiceStack.Northwind.ServiceInterface
{
using Caching;
using ServiceModel.Operations;
public class CachedCustomersService : Service
{
public ICacheClient CacheClient { get; set; }
public object Get(CachedCustomers request)
{
return base.Request.ToOptimizedResultUsingCache(
this.CacheClient, "urn:customers", () => {
var service = this.ResolveService<CustomersService>();
return service.Get(new Customers());
});
}
}
public class CachedCustomerDetailsService : Service
{
public ICacheClient CacheClient { get; set; }
public object Get(CachedCustomerDetails request)
{
var cacheKey = UrnId.Create<CustomerDetails>(request.Id);
return base.Request.ToOptimizedResultUsingCache(
this.CacheClient, cacheKey, () =>
this.ResolveService<CustomerDetailsService>().Get(new CustomerDetails { Id = request.Id }));
}
}
public class CachedOrdersService : Service
{
public ICacheClient CacheClient { get; set; }
public object Get(CachedOrders request)
{
var cacheKey = UrnId.Create<Orders>(request.CustomerId ?? "all", request.Page.GetValueOrDefault(0).ToString());
return base.Request.ToOptimizedResultUsingCache(CacheClient, cacheKey,
() => (OrdersResponse) ResolveService<OrdersService>()
.Get(new Orders { CustomerId = request.CustomerId, Page = request.Page }));
}
}
}