首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何提高响应时间

如何提高响应时间
EN

Stack Overflow用户
提问于 2012-10-30 11:35:59
回答 2查看 254关注 0票数 2

我使用的是最新版本的ServiceStack。我在服务栈提供的内存缓存中使用,因为我的服务正在从速度较慢的数据库读取数据。

实现所有这些后,服务响应时间为5-7秒,这太慢了。有没有可能对其进行优化,使其更具响应性。

以下是我的概念代码:

代码语言:javascript
运行
复制
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.
    }
}
EN

回答 2

Stack Overflow用户

发布于 2012-10-30 20:50:31

您可以查看http缓存来帮助您的请求。有关更多信息,请查看here

票数 0
EN

Stack Overflow用户

发布于 2012-10-30 23:30:17

您可能应该使用ServiceStack中内置的缓存模式,例如:

代码语言:javascript
运行
复制
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请求)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13132268

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档