标签: phpfastcache

当我从缓存中获取它时,fetch只返回一行

我正在尝试采用缓存类在我的网页上使用.

简单的逻辑是这样的:

尝试从缓存中获取数据:

  • 如果没有:运行查询并将其设置为缓存.
  • 如果有:显示来自缓存的数据.

我的代码

<?php
// Require Library
require_once("phpfastcache.php");
$cache = phpFastCache();

//lets get it from cache.
$r = $cache->get("cachethis");

if($r == null) {

    echo " THIS TIME RUN WITHOUT CACHE <br> ";
    $time_start = microtime(true);

    $query = $handler->query("SELECT * FROM members");
        while($r = $query->fetch(PDO::FETCH_ASSOC)) {

        //echo
        echo "$r[id]";

        //lets cache query above.
        $cache->set("cachethis", $r, 10);

        }

    $time_end = microtime(true);
    $time = ($time_end - $time_start);
    echo "<p>done in " . $time . " seconds</p>";

} 
//if ($r != …
Run Code Online (Sandbox Code Playgroud)

php mysql pdo caching phpfastcache

5
推荐指数
1
解决办法
104
查看次数

标签 统计

caching ×1

mysql ×1

pdo ×1

php ×1

phpfastcache ×1