我与 Simple PHP File Cache 一起工作类(class)。我使用 foreach
方法将数据集(添加 MySQL
结果)添加到 PHP 循环
中,如下所示:
PHP 代码:
$c = new Cache();
foreach($_POST['audio'] as $audio){
SQL::put("INSERT INTO " . NEWS_FILES . " (news_id, url, type) VALUES (?, ?, ?)", $id, $audio,"audio");
$c->store($id, array(
'action' => array(
$id, $video,"audio")
));
}
缓存文件中的结果:
{"202":{"time":1410452801,"expire":0,"data":{"action":[202,"http:\/\/localhost\/user\/uploads\/files\/1\/thumbs\/1\/audio\/download-kid-photo-c.jpg","audio"]}}}
现在,我有 4 个 id 202 的文件,但缓存类只在文件中插入一个文件。缓存类不适用于循环!如何解决这个问题?
类文件 HERE
最佳答案
这是由覆盖缓存中的标识符引起的。 这就像 nosql 键值存储一样。键应该是唯一标识符。 你已经:
202 => file1,
202 => file2,
202 => file3,
202 => file4
并且不可能通过标识符获取每个文件。 它应该看起来像:
201 => file1,
202 => file2,
203 => file3,
204 => file4
关于PHP 文件缓存不能在循环中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25822678/