Memcached 存储数据但不返回任何内容...?

发布于 2025-01-07 08:01:55 字数 664 浏览 2 评论 0原文

我有这个 CakePHP 数组,它会定期更新(一个小时左右)并存储到 memcached 中。最近,我更改了数组的结构,以便更容易在视图中使用,但我仍然使用相同的名称/键来缓存它。但是,我遇到了这个问题,偶尔,视图会变得混乱(数组中的数据进入无序列表,如果数组返回空,则它设置为不显示任何内容)。

但奇怪的是,在我的控制器代码中,我有类似的逻辑(有点伪代码):

$list_array = array();
if(cache_read('key', 'controller_name')) {
     $list_array = &cache_read('key', 'controller_name');
}
else {
     $list_array = $this->Model->function_that_generates_the_same_array();
     cache_write('key', $list_array, 'controller_name');
}

所以无论如何,应该填充数组。

唯一改变的是数组的结构,但我不确定是 Memcached 出了问题,还是我的代码出了问题。我倾向于 memcached 是问题所在,因为在更改之前我从未遇到过此问题。

有什么想法吗?见解?我对 memcached 相当陌生,因此非常感谢您的帮助。谢谢!

I have this CakePHP array that is updated periodically (an hour or so) and stored into memcached. Recently, I changed the structure of the array so it's easier to work with in a view but I still cache it with the same name / key. However, I'm running into this problem where once in a while, the view goes screwy (the data in the array goes into an unordered list, and if the array returns empty, it's set to not show anything).

The strange thing though is that in my controller code, I have logic like (somewhat-pseudo code):

$list_array = array();
if(cache_read('key', 'controller_name')) {
     $list_array = &cache_read('key', 'controller_name');
}
else {
     $list_array = $this->Model->function_that_generates_the_same_array();
     cache_write('key', $list_array, 'controller_name');
}

So regardless, the array should be populated.

The only thing that has changed is the structure of the array, but I'm not sure whether it's something with Memcached that's wrong, or my code. I'm leaning towards memcached being the issue because I've never had this issue before prior to the change.

Any thoughts? Insights? I'm rather new to memcached so any help is appreciated. Thanks!

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

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

发布评论

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

评论(1

沉睡月亮 2025-01-14 08:01:55

您是否尝试过手动连接到 memcached 服务器并验证存储在其中并返回的内容?

尝试(将 localhost 更改为您的 memcached 服务器):

telnet localhost 11211
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
get key

Have you tried manually connecting to your memcached server and validating what is stored there and returned?

Try (change localhost to your memcached server):

telnet localhost 11211
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
get key
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文