缓存认证数据

发布于 2024-08-28 06:40:28 字数 666 浏览 5 评论 0原文

我目前正在使用 CouchDB 和 RESTlet 实现 REST Web 服务。 RESTlet 层主要用于身份验证和对 CouchDB 提供的 JSON 数据进行一些小的过滤:

Clients <= HTTP => [ RESTlet <= HTTP ==> CouchDB ]

我还使用 CouchDB 来存储用户登录数据,因为我不想为此目的添加额外的数据库服务器。因此,对我的服务的每个请求都会导致 RESTlet 执行两个 CouchDB 请求(身份验证数据+“真实”请求)。为了保持服务尽可能高效,我想减少请求数量,在本例中是对登录数据的冗余请求。

我现在的想法是在我的 RESTlet 应用程序中提供一个缓存(即通过 LinkedHashMap 的 LRU 缓存)来缓存登录数据,因为 HTTP 缓存可能不够。但是,例如,一旦用户更改密码,如何使缓存数据无效。感谢 REST,应用程序可以在多个服务器上并行运行,并且我不想创建一个中央实例只是为了缓存登录数据。

目前,我将请求的身份验证数据保存在缓存中,并尝试使用它们对新请求进行身份验证。如果身份验证失败或现在有可用条目,我将向我的 CouchDB 存储发送 GET 请求,以获取实际的身份验证数据。 因此,在最坏的情况下,已更改数据的用户可能仍然可以使用旧凭据登录。我该如何处理呢?

或者什么是保持缓存最新的好策略?

提前致谢。

I'm currently implementing a REST web service using CouchDB and RESTlet. The RESTlet layer is mainly for authentication and some minor filtering of the JSON data served by CouchDB:

Clients <= HTTP => [ RESTlet <= HTTP => CouchDB ]

I'm using CouchDB also to store user login data, because I don't want to add an additional database server for that purpose. Thus, each request to my service causes two CouchDB requests conducted by RESTlet (auth data + "real" request). In order to keep the service as efficent as possible, I want to reduce the number of requests, in this case redundant requests for login data.

My idea now is to provide a cache (i.e.LRU-Cache via LinkedHashMap) within my RESTlet application that caches login data, because HTTP caching will probabily not be enough. But how do I invalidate the cache data, once a user changes the password, for instance. Thanks to REST, the application might run on several servers in parallel, and I don't want to create a central instance just to cache login data.

Currently, I save requested auth data in the cache and try to auth new requests by using them. If a authentication fails or there is now entry available, I'll dispatch a GET request to my CouchDB storage in order to obtain the actual auth data.
So in a worst case, users that have changed their data will perhaps still be able to login with their old credentials. How can I deal with that?

Or what is a good strategy to keep the cache(s) up-to-date in general?

Thanks in advance.

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

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

发布评论

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

评论(2

水中月 2024-09-04 06:40:28

在我看来,您似乎已经成长到足以使用一些“专业”缓存解决方案(例如 EHCache)。所有分布式缓存都允许新的数据复制和复制不同节点之间的失效,所以你的问题已经解决了。

To me it looks like you've grown up far enough to use some "professional" cache solution (e.g. EHCache). All distributed caches allow new data replication & invalidation among different nodes so your problem is already solved.

故人爱我别走 2024-09-04 06:40:28

像 memcached 这样的分布式内存缓存可能就是您正在寻找的。您可以配置对象年龄、缓存大小,还可以公开回调以从缓存中删除特定对象(例如当信息过时时)。

A distributed in-memory cache like memcached might be what you are looking for. You can configure object age, cache size and also expose callbacks to remove specific objects from the cache (like when the information is stale).

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