1

phpFastCache をアプリケーションに統合しようとしています。

これは、ドキュメントで述べられていることです:

<?php
    // try to get from Cache first.
    $html = phpFastCache::get(array("files" => "keyword,page"));

    if($html == null) {
        $html = Render Your Page || Widget || "Hello World";
        phpFastCache::set(array("files" => "keyword,page"),$html);
    }

    echo $html;
?>

「RENDER YOUR PAGE」を自分のページに置き換える方法が見つかりませんでした。「include」、「get_file_content」を試しました...どれも機能しません。

誰でも私に例を教えてください。

ありがとうございました

4

1 に答える 1

3

元の PHP コードを呼び出した後にブラウザーに送信される、生成されたコンテンツを取得するには、出力バッファー メソッドを使用する必要があります。

これは、上記の例で PHP ファイルをインクルードし、将来のリクエストのために結果をキャッシュする方法です。

<?php
    // try to get from Cache first.
    $html = phpFastCache::get(array("files" => "keyword,page"));

    if($html == null) {
        // Begin capturing output
        ob_start();

        include('your-code-here.php'); // This is where you execute your PHP code

        // Save the output for future caching
        $html = ob_get_clean();

        phpFastCache::set(array("files" => "keyword,page"),$html);
    }

    echo $html;
?>

出力バッファの使用は、PHP でキャッシュを実行する非常に一般的な方法です。使用しているライブラリ (phpFastCache) には、代わりに使用できる組み込み関数がないようです。

于 2013-07-29T22:29:59.097 に答える