WCF 服务:ASP.NET 缓存或 SQL
我目前正在开发将在 Microsoft Azure 上运行的 WCF REST Web 服务。为了限制每个 IP 地址的请求数量以防止滥用,我当前使用 ASP.NET 缓存存储 IP 和超时。
此方法效果很好,但由于 Azure 的多个 VM 实例不共享单个缓存,因此请求可能会在不同 VM 之间拆分,并在 VM 重置时被清除。
我不认为这是一个主要问题,但由于我已经将用户信息存储在 SQL Azure 数据库中并使用 WCF 服务对用户进行身份验证,因此使用数据库而不是 ASP.NET 缓存会更好吗?
任何adive都会非常有帮助。
I'm currently developing a WCF REST Web Service that will be running on Microsoft Azure. To limit the number of requests per IP address to prevent abuse, I currently store the IP and timeout using the ASP.NET Cache.
This method works great but since muliple VM instances with Azure don't share a single cache, the requests could be split between different VMs and be cleared if a VM is reset.
I don't think this is a major problem but since I already store user info in a SQL Azure database and authenticate users using the WCF service, would I be better off using the database instead of the ASP.NET cache?
Any adive would be really helpful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用混合方法怎么样?除了将其放入缓存之外,您还可以将其存储到 SQL 数据库中。然后,当它们到达不同的实例时,它会与数据库中存储的时间一起放入缓存中。最大限度地减少数据库的往返次数,并使信息可供所有服务器使用。
What about using a hybrid approach? You could store it into the SQL database in addition to putting it in your cache. Then when they hit a different instance it is put into the cache with the time that was stored in the database. Minimizes round trips to the database, and makes the information available to all of the servers.
您必须决定何时可以接受阈值。
来自缓存的数据会更快,但存在不代表实际当前数据的风险。从数据库获取数据是新鲜事,但往返数据库需要时间。
You have to decide when the threshold is acceptable.
Data from cache will be faster, but there's a risk it doesn't represent actual current data. Where fetching data from the database is fresh, but it takes time to make the trip to the database and back.