Is it possible to use ASP.NET application caching in web API?

后端 未结 4 1494
北荒
北荒 2021-01-19 23:15

For example, in a ASP.NET page you would do something like

Cache.Add({...}) and access it via Cache[\"key\"]. In this context, Cache is th

4条回答
  •  失恋的感觉
    2021-01-19 23:42

    Take a look at the MemoryCache class. From its MSDN documentation:

    The MemoryCache class is similar to the ASP.NET Cache class. The MemoryCache class has many properties and methods for accessing the cache that will be familiar to you if you have used the ASP.NET Cache class. The main differences between the Cache and MemoryCache classes are that the MemoryCache class has been changed to make it usable by .NET Framework applications that are not ASP.NET applications.

    You can create a new instance of a MemoryCache yourself, or you can use the default AppDomain-wide instance via the MemoryCache.Default static property.

    Edit: You'll need to add a reference to System.Runtime.Caching.dll if you wish to use this type.

提交回复
热议问题