我为缓存的MySQL结果找到了phpfastcahce类。支持WinCache、MemCache、Files、X-Cache、APC Cache的详细信息,比如:
PHP Caching Class For Database : Your website have 10,000 visitors who are online, and your dynamic page have to send 10,000 same queries to database on every page load. With phpFastCache, your page only send 1 query to DB, and use the cache to serve 9,999 other visitors.
示例代码中:
<?php
// In your config file
include("php_fast_cache.php");
// This is Optional Config only. You can skip these lines.
// phpFastCache support "apc", "memcache", "memcached", "wincache" ,"files", "pdo", "mpdo" and "xcache"
// You don't need to change your code when you change your caching system. Or simple keep it auto
phpFastCache::$storage = "auto";
// End Optionals
// In your Class, Functions, PHP Pages
// try to get from Cache first.
$products = phpFastCache::get("products_page");
if($products == null) {
$products = YOUR DB QUERIES || GET_PRODUCTS_FUNCTION;
// set products in to cache in 600 seconds = 10 minutes
phpFastCache::set("products_page",$products,600);
}
foreach($products as $product) {
// Output Your Contents HERE
}
?>
现在,在我的网站索引中,我有任何显示最后新闻、最佳新闻、世界新闻的块。。。。。为了缓存我的索引,我必须使用phpfastcache缓存每个块(last news, best news, world news ..... )
的MySQL
结果,如果我编辑现有新闻或添加新新闻,则在管理页面中删除所有缓存?这是真的吗?
缓存MySQL
结果的最佳方式是什么?我的索引页使用phpfastcache(任何方法)?!
phpfastcache不能uderst并且您的数据是否已更改
在数据库中的特定数据更改后,您必须执行某些操作
首页缓存中的第一个代码必须是这样的:
$lastnews = phpFastCache::get('index_lastnews');
$bestnews = phpFastCache::get('index_bestnews');
$worldnews = phpFastCache::get('index_worldnews');
if($lastnews == null) {
$lastnews = YOUR DB QUERIES || GET_DATA_FUNCTION;
phpFastCache::set('index_lastnews',$lastnews,600);
}
if($bestnews == null) {
$bestnews = YOUR DB QUERIES || GET_DATA_FUNCTION;
phpFastCache::set('index_bestnews',$bestnews,600);
}
。.
并且在您的管理页面中,当特定数据更改时,缓存代码必须如下所示:
AFTER DATABASE insert | update ....
您可以通过以下两种方式替换旧的缓存:
1) 删除缓存(删除缓存后,第一次访问后自动重建缓存)
phpFastCache::delete('index_lastnews');
2) 更新缓存
$lastnews = YOUR DB QUERIES || GET_DATA_FUNCTION;
phpFastCache::set("index_lastnews",$lastnews,600);