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

发布于 2024-09-14 09:23:56 字数 264 浏览 3 评论 0原文

使用 HttpCache 缓冲来自 Web 服务的数据(而不是将相同的数据存储在数据库表中)可能会遇到哪些问题?在假设的情况下,服务暂时不可用,如果服务器需要在此期间重新启动,则将无法重新填充缓存。因此,是否可以像处理 SqlServer 会话状态一样保留缓存?

我读到 HttpCache 是使用 Singleton 模式实现的。这是否意味着我在处理来自缓存的对象时应该使用互斥体?

如果缓存一方面由单独的线程进程更新,同时又由不同的线程读取,会发生什么?

谢谢。

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? 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?

I read the HttpCache is implemented using the Singleton pattern. Does that mean I should be using Mutex when working with objects coming from the cache?

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

記憶穿過時間隧道 2024-09-21 09:23:56

缓存机制遇到的最大问题是过时的数据。由于数据已被缓存,因此它的历史可以与缓存生命周期一样长。在事务系统中,这是不可接受的,但对于其他系统来说,这很好。只需了解数据的年龄即可。我不知道缓存是否可以持久化,但是如果您考虑使用数据库来实现这一点,我建议首先不要使用缓存,因为部分原因是快速内存访问到您的数据。

是的,缓存使用像单例这样的集中式内存存储。关于互斥锁的问题的答案是,它取决于您的数据访问模式。大多数人使用缓存来填充一次数据。如果该值超时,缓存将清空其条目并重新填充。是的,您可以使用互斥锁(或更可能是lock 语句)来保护访问,以防止多个客户端同时填充缓存。但在我看来,这更多的是一个性能点,而不是数据一致性点,因为客户端很可能会使用相同的数据相互写入(同样,这确实取决于您的情况)。

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. The answer to your question on Mutexes is that it depends on your data access patterns. 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. 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文