我使用简单PHP文件缓存类。我使用foreach
方法将数据集(添加MySQL
结果)添加到PHP loops
中,如下所示:
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