首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >php缓存动态索引页

php缓存动态索引页
EN

Stack Overflow用户
提问于 2014-09-23 19:06:35
回答 1查看 678关注 0票数 3

我为缓存的凤尾草结果找到了MySQL类。支持WinCache、MemCache、Files、WinCache、WinCache的详细信息如下:

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.

在示例代码中:

代码语言:javascript
复制
<?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结果使用(last news, best news, world news ..... )和在管理页删除所有缓存,如果我编辑现有的新闻或添加新的新闻?这是一种真实的方式?

使用phpfastcache(any方法缓存MySQL结果的最佳方法是什么?!

EN

回答 1

Stack Overflow用户

发布于 2014-09-23 19:38:20

phpfastcache无法备份您的数据是否已更改

在数据库中的特定数据发生更改后,必须进行一些操作。

首先,主页缓存代码必须如下所示:

代码语言:javascript
复制
$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);
}

。。。

在您的管理页面中,当特定数据更改时,缓存代码必须如下所示:

代码语言:javascript
复制
AFTER DATABASE insert | update ....

您可以通过以下两种方式替换旧缓存:

1)删除缓存(删除缓存后,第一次访问后缓存自动重建)

代码语言:javascript
复制
phpFastCache::delete('index_lastnews');

2)更新缓存

代码语言:javascript
复制
$lastnews =   YOUR DB QUERIES || GET_DATA_FUNCTION;
phpFastCache::set("index_lastnews",$lastnews,600);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26002825

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档