简体   繁体   English

使用ASP.NET HttpCache缓冲Web服务中的数据

[英]Using ASP.NET HttpCache to buffer data from a web service

What problems might I encounter by using the HttpCache to buffer data from a web service, as opposed to storing the same data in a database table? 与使用相同的数据存储在数据库表中相反,使用HttpCache缓冲来自Web服务的数据可能会遇到什么问题? In a hypothetical situation whereby the service was temporarily unavailable, if the server needed to reboot during that time there would be no way to re-populate the cache. 在假设情况下,该服务暂时不可用,如果服务器需要在这段时间内重新启动,则无法重新填充缓存。 So for that reason, is it possible to persist the cache like you could do with SqlServer Session state? 因此,由于这个原因,是否可以像使用SqlServer Session状态那样持久化缓存?

I read the HttpCache is implemented using the Singleton pattern. 我阅读了使用Singleton模式实现的HttpCache。 Does that mean I should be using Mutex when working with objects coming from the cache? 这是否意味着在处理来自缓存的对象时应该使用Mutex?

What will happen if the cache is being updated on the one hand by a separate threaded process while also being read by a different thread? 如果一方面通过单独的线程进程更新缓存,同时又由其他线程读取缓存,将会发生什么情况?

Thanks. 谢谢。

The biggest problem you'll encounter with a caching mechanism is stale data. 缓存机制将遇到的最大问题是过时的数据。 Since data is cached, it can be as old as the cache lifetime. 由于数据已被缓存,因此它可能与缓存生存期一样旧。 In transactional systems, this is unacceptable, but for other systems, it's fine. 在事务系统中,这是不可接受的,但是对于其他系统,这很好。 Just understand how old the data is. 只要了解数据有多旧即可。 I don't know if the cache can be persisted, but if you're thinking of going to a database to do so, I would recommend against using a cache in the first place, since part of the point is fast in-memory access to your data. 我不知道缓存是否可以持久化,但是如果您打算进入数据库,那么我建议您不要使用缓存,因为其中的一部分是快速的内存访问对您的数据。

Yes, caching uses a centralized in-memory store like a Singleton. 是的,缓存使用诸如Singleton之类的集中式内存存储。 The answer to your question on Mutexes is that it depends on your data access patterns. 有关Mutexes的问题的答案是,这取决于您的数据访问模式。 Most people use caches to populate data once. 大多数人使用缓存一次填充数据。 If the value times out, the cache nulls out their entry and they repopulate. 如果该值超时,则高速缓存会将其条目清空,然后重新填充它们。 Yes, you could protect the access with a Mutex (or more likely a lock statement) to prevent multiple clients from racing to populate the cache all at once. 是的,您可以使用Mutex(或更可能是lock语句)来保护访问,以防止多个客户端竞相一次全部填充缓存。 But IMO that's more of a performance point than a data-consistence point, since in all probability the clients will be writing over one another with the same data (again, it does depend on your situation). 但是,IMO比数据一致性点更重要的是性能点,因为客户端很可能会使用相同的数据相互重写(同样,这确实取决于您的情况)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM