我使用的是最新版本的ServiceStack。我在服务栈提供的内存缓存中使用,因为我的服务正在从速度较慢的数据库读取数据。
实现所有这些后,服务响应时间为5-7秒,这太慢了。有没有可能对其进行优化,使其更具响应性。
以下是我的概念代码:
public class CustomerService : Service
{
public object Any(Customer request)
{
string cacheKey = "customerReport_" + request.Id;
report = CacheClient.Get<BalanceReport>(cacheKey);
if(report != null)
return report;
//Logic to build report.
//I am caching the report object here before returning report.
}
}
发布于 2012-10-30 20:50:31
您可以查看http缓存来帮助您的请求。有关更多信息,请查看here。
发布于 2012-10-30 23:30:17
您可能应该使用ServiceStack中内置的缓存模式,例如:
public class CustomerService : Service
{
public object Any(Customer request)
{
string cacheKey = "customerReport_" + request.Id;
return base.RequestContext.ToOptimizedResultUsingCache(
this.CacheClient, cacheKey, () => {
//Logic to build report.
//I am caching the report object here before returning report.
return repo.GetCustomerReport(request.Id);
});
}
}
你可以阅读更多关于ServiceStack Caching on the wiki的内容。基本上,它将最优的web服务响应存储在缓存中,例如Deflate/压缩的JSON字节(如果是JSON请求)。
https://stackoverflow.com/questions/13132268
复制相似问题