内存缓存共享

发布于 2024-07-14 03:34:51 字数 92 浏览 4 评论 0原文

是否可以在多个项目之间共享单个 Memcache 实例。

假设我将一个对象推送到一个项目的内存缓存中,我是否可以从不同的项目中检索相同的对象。 ?

Is it possible to share a single instance of a Memcache between multiple projects.

Suppose I push one object inside the memcache in one project, is it possible for me to retrieve the same object from a different project. ?

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

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

发布评论

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

评论(4

方觉久 2024-07-21 03:34:51

Memcache 只是一个内存存储。 它可以跨多台机器运行。 两个完全不同的进程没有理由不能通过它相互通信。

让我澄清一下。 您可以在一台或多台服务器上运行 memcache。 您可以将客户端配置为与一组特定的实例通信。 您可以在同一主机上运行两个(或更多)不同的 memcache 进程(侦听不同的 IP 地址和/或端口),并且它们是完全独立的。

如果您的两个应用程序与相同的实例通信,那么它们没有理由无法通信。

如果您与多个实例通信并对数据进行分区(即,将其拆分到不同的实例中),那么您的客户端需要知道从哪个实例获取数据或将数据放入哪个实例,那么情况就会变得复杂。 如果您使用相同的客户端库(例如,您的两个客户端都是 PHP5),那么这并不是什么戏剧性的事情。 如果它们不相同,那么您必须以某种方式处理该问题。

如果您使用不同的技术,另一个问题是您必须考虑交换格式,因为 PHP 中的自定义序列化在 Java 或 C# 中不那么可读。 典型的选择是 XML 甚至 JSON。

Memcache is just a memory store. It can run across multiple machines. There's no reason that two entirely different processes can't talk to each other via it.

Let me clarify. You can run memcache on one or more servers. You can configure your clients to speak to a specific set of instances. You can run two (or more) different memcache processes on the same host (listening to different IP addresses and/or ports) and they're completely independent.

If your two applications talk to the same instance(s) then there's no reason they can't communicate.

The complication comes if you talk to multiple instances and partition your data (ie split it across different instances) then your clients need to know which instance to get the data from or put the data into. If you're using the same client library (eg both your clients are PHP5) then that's not a drama. If they aren't the same then you have to handle that problem somehow.

The other issue if you use different technologies is you have to think about the interchange format since the custom serialization in PHP won't be so readable in Java or C#. Typical choices are XML or even JSON.

你的背包 2024-07-21 03:34:51

是的,只要每个项目以相同的方式配置memcache节点,并以相同的方式为缓存元素生成密钥,它们就可以共享数据。

Yes, as long as each project configures the memcache nodes in same the way, and generates a key for a cache element in the same way, they can share data.

软糖 2024-07-21 03:34:51

如果您担心安全问题(一个应用程序读取另一个应用程序的数据)或应用程序之间的缓存中毒,那么这些都是可能的。

如果要在应用程序之间隔离 memcache,则可以在单个服务器上运行多个 memcached 守护程序,每个守护程序使用服务器的一部分内存。 每个实例都在不同的端口号上运行。 您可以使用防火墙规则来确保只有特定的应用程序服务器可以访问特定的 memcache 端口,以确保应用程序无法读取或毒害彼此的数据。

If you are worried about security concerns (one app reading another's data) or cache poisoning between applications those are possibilities.

If you want to isolate memcache between applications, then you can run multiple memcached daemons on a single server, each using a portion of the server's memory. Each instance runs on a different port number. You can use firewall rules to ensure that only specific application servers have access to specific memcache ports to ensure that applications can not read or poison each other's data.

夏の忆 2024-07-21 03:34:51

对于每个项目,我将提供一种方法来生成密钥并按命名空间分区项目。
因此,对于项目 B 中的 key = foo,它由 A.foo 存储/获取,而项目 B 中的 foo 称为 B.foo 等。

这样它应该可以工作。
然而,当涉及到生产时,这种方法是非常不鼓励的,因为你可能会陷入调试的地狱(性能/可靠性等)。

更好的方法是在不同端口上运行多个内存缓存实例,恕我直言,这更干净。

For each of the project I would provide a method to generate keys and partition projects by namespace.
So for key = foo from project B, it is stored/fetched by A.foo, and foo from project B is called B.foo etc.

This way it should work.
However when comes to production, this approach is very discouraged, since you can be in hell of debugging (performance/reliability etc).

Better way is to have multiple instances of memcache running on different port, this is more clean IMHO.

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