如何使用高速缓存中的ASP.NET Web API? [英] How to use caching in ASP.NET Web API?

查看:79
本文介绍了如何使用高速缓存中的ASP.NET Web API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ASP.NET MVC 4 WEB API

I am using ASP.NET MVC 4 with WEB API

我有以下动作,如下图所示的动作,我的服务方法,使一个数据库调用 DoMagic()方法,并返回对此我然后使用一个整数值每一页上,这个动作是用Ajax调用调用。

I have the following action, in the action shown below, my service method makes a db call to DoMagic() method and returns an integer value which I am then using on every page, this action is called using an ajax call.

下面是我的WEB API动作:

Below is my WEB API action :

[OutputCache(Duration = 86400, VaryByParam = "none")]
[ActionName("GetMyMagicNumber")]
public int GetMyMagicNumber()
{
    if (WebSecurity.IsAuthenticated)
    {
        var revenue = _magicService.DoMagic();
        return revenue;
    }
    return 0;
}

我的问题:我haved使用试过 [的OutputCache(持续时间= 86400,的VaryByParam =无)] ,我除外,只有在第一次分贝的通话将被制成,该动作下后续请求将返回箱缓存的值,但这种情况并非如此。

My question : I haved tried using [OutputCache(Duration = 86400, VaryByParam = "none")] and I excepted that only the first time the db call will be made and next subsequent request to this action will return me the cached value, but this is not happening.

一个DB调用再次提出,该数据库调用需要一定的时间,我如何得到这个工作?

A db call is again made, the db call takes time how do I get this working ?

推荐答案

不幸的是,高速缓存中没有内置的ASP.NET Web API。

Unfortunately, caching is not built into ASP.NET Web API.

检查了这一点,让您的轨道上:<一href=\"http://www.strathweb.com/2012/05/output-caching-in-asp-net-web-api/\">http://www.strathweb.com/2012/05/output-caching-in-asp-net-web-api/

Check this out to get you on track: http://www.strathweb.com/2012/05/output-caching-in-asp-net-web-api/

这是更新的资源在这里:<一href=\"https://github.com/filipw/AspNetWebApi-OutputCache\">https://github.com/filipw/AspNetWebApi-OutputCache

An updated resource here: https://github.com/filipw/AspNetWebApi-OutputCache

这篇关于如何使用高速缓存中的ASP.NET Web API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆