例如,在一个ASP.NET页面,你会做这样的事情
For example, in a ASP.NET page you would do something like
Cache.Add({...})
并通过访问其缓存[钥匙]
。在这种情况下,缓存是的System.Web.Caching.Cache
对象。
Cache.Add({...})
and access it via Cache["key"]
. In this context, Cache is the System.Web.Caching.Cache
object.
反正有做这种类型的ASP.NET应用程序级缓存的Web API控制器?
Is there anyway to do this type of ASP.NET application level caching in web API controllers?
如果你是虚拟主机,为什么不呢?
If you are web hosting, why not?
var context = HttpContext.Current;
if (context != null)
{
if (context.Cache["g"] == null)
{
context.Cache["g"] = 9.81;
}
}
但是,你正在对ASP.NET依赖这样做。正如你可能知道,的ASP.NET Web API虽然已经ASP.NET中的名称是主机无关,ASP.NET/IIS不是唯一的宿主选项。它可以是自托管为好。东西给你才走这路线来考虑。
But you are taking a dependency on ASP.NET by doing so. As you might know, ASP.NET Web API though has ASP.NET in the name is host-agnostic and ASP.NET/IIS is not the only hosting option. It can be self-hosted as well. Something for you to consider before going down that route.