【发布时间】:2014-09-24 03:38:20
【问题描述】:
我找到phpfastcahce 缓存 MySQL 结果的类。详细说明支持 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 结果如果我编辑现有新闻或添加新新闻,则在管理页面中删除所有缓存?这是真道?
使用 phpfastcache(任何方法)缓存 MySQL 结果我的索引页面的最佳方法是什么?!
【问题讨论】:
-
不特定于 phpfastcache(我对此并不熟悉),但通常在使用任何缓存时,您需要制定有关如何处理缓存未命中的策略(即查询数据库并使用结果填充缓存) 并处理缓存中的无效/清除项目(在更改为基础数据时清除缓存条目,为缓存项目应用 TTL)等。
-
回答解决了你的问题吗?