在网页API缓存数据 [英] Caching Data in Web API

查看:171
本文介绍了在网页API缓存数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有必要去缓存对象的集合,主要是静态的(可能有1个,每天的变化),这是在我的ASP.NET Web API的OData服务avaliable。这个结果集是通过调用(即客户端不调用特定)使用,所以它需要在应用层被缓存。

I have the need to cache a collection of objects that is mostly static (might have changes 1x per day) that is avaliable in my ASP.NET Web API OData service. This result set is used across calls (meaning not client call specific) so it needs to be cached at the application level.

我做了一堆关于在网络API缓存,但所有的结果都是关于输出缓存搜索的。这是不是我要找的在这里。我想缓存一个'人'的收集将在后续调用(可能有一个滑动过期)。

I did a bunch of searching on 'caching in Web API' but all of the results were about 'output caching'. That is not what I'm looking for here. I want to cache a 'People' collection to be reused on subsequent calls (might have a sliding expiration).

我的问题是,因为这还只是ASP.NET,我用传统的应用程序缓存技术在内存中坚持此集合,或者是有别的东西,我需要做什么?这个集合是<青霉>不的直接返回给用户,而是用作场景经由API调用的OData查询后面的来源。没有任何理由让我出去到数据库在每次调用得到的确切的同在每次调用的信息。它到期小时就足够了。

My question is, since this is still just ASP.NET, do I use traditional Application caching techniques for persisting this collection in memory, or is there something else I need to do? This collection is not directly returned to the user, but rather used as the source behind the scenes for OData queries via API calls. There is no reason for me to go out to the database on every call to get the exact same information on every call. Expiring it hourly should suffice.

任何一个知道如何正确缓存此方案中的数据?

Any one know how to properly cache the data in this scenario?

推荐答案

是的,输出缓存是不是你在找什么。可以用的MemoryCache缓存存储器中的数据,例如,<一href=\"http://msdn.microsoft.com/en-us/library/system.runtime.caching.memorycache.aspx\">http://msdn.microsoft.com/en-us/library/system.runtime.caching.memorycache.aspx 。但是,如果应用程序池被回收,你将丢失的数据。另一个选择是使用分布式缓存像的AppFabric缓存或MEMCACHE仅举几。

Yes, output caching is not what you are looking for. You can cache the data in memory with MemoryCache for example, http://msdn.microsoft.com/en-us/library/system.runtime.caching.memorycache.aspx . However, you will lose that data if the application pool gets recycled. Another option is to use a distributed cache like AppFabric Cache or MemCache to name a few.

这篇关于在网页API缓存数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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