我目前正试图在我的Web应用程序中实现作为数据存储的APC缓存。
目前,系统直接从MySQL数据库中检索数据,并且每个请求都需要一个数据库调用。
我目前正试图通过用在每次请求时从缓存截获并提供服务的数据预填充缓存来更改这一点。
现在的方法是:
if(!empty($_GET['id'])){
$app = $db->real_escape_string($_GET['id']);
$result = $db->query("SELECT * FROM pages_content WHERE id = $app");
$rawdata = $result->fetch_assoc();
}
数据通过以下方式输出:
$title = stripslashes($rawdata['title']);
$meta['keywords'] = stripslashes($rawdata['htmlkeywords']);
$meta['description'] = stripslashes($rawdata['htmldesc']);
$subs = stripslashes($rawdata['subs']);
$pagecontent = "<article>".stripslashes($rawdata['content'])."</article>";
我需要预填充脚本对数据表中的每一行数据进行缓存。然后,服务脚本将能够在需要时从缓存中提取数据,使用诸如
apc_fetch('[columname][id]')
.
我怎么能设计出这个?
我想我需要序列化数据?