打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
PHP缓存动态索引页面

我为缓存的MySQL结果找到了phpfastcahce类.支持WinCache,MemCache,文件,X-Cache,APC Cache的详细信息,并说:

数据库的PHP缓存类:您的网站有10,000个在线访问者,而动态页面在每次加载页面时都必须向数据库发送10,000个相同的查询.使用phpFastCache,您的页面仅向数据库发送1个查询,并使用缓存为9,999个其他访问者提供服务.

在示例代码中:

<?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    }?>

现在,在我的网站索引中,我有任何块可以显示最新新闻,最佳新闻,国际新闻…..为了缓存我的索引,我必须为每个块(最新新闻,最佳新闻,国际新闻)缓存MySQL结果. ….)如果我编辑现有新闻或添加新新闻,请使用phpfastcache并在管理页面中删除所有缓存.这是真的吗?

缓存MySQL的最佳方法是什么,最好的方法是使用phpfastcache(任何方法)?

解决方法:

phpfastcache无法理解您的数据是否已更改

在数据库中的特定数据更改后,您必须执行某些操作

首先在首页缓存中的代码必须是这样的:

$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);
来源:https://www.icode9.com/content-1-570601.html
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
PHP面试题及答案
用PHP实现从任何位置(包括未下载的位置)播放flv
更改Apache默认起始(索引)页面:DirectoryIndex
创建WordPress存档索引
直播带货源码,缓存的高低速从哪些方面体现
MySQL性能优化的最佳20+条经验
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服