Memcached 存储数据但不返回任何内容...?
我有这个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过手动连接到 memcached 服务器并验证存储在其中并返回的内容?
尝试(将 localhost 更改为您的 memcached 服务器):
Have you tried manually connecting to your memcached server and validating what is stored there and returned?
Try (change localhost to your memcached server):