2

HTTP キャッシュとは何ですか? Slim 3 での使用方法を教えてください。

しかし、これがSlim 3でどのように行われるかはよくわかりません:

use Slim\Http\Request;
use Slim\Http\Response;

require_once __DIR__ . '/../vendor/autoload.php';

// Register service provider with the container
$container = new \Slim\Container;
$container['cache'] = function () {
    return new \Slim\HttpCache\CacheProvider();
};

$app = new \Slim\App($container);

// Add middleware to the application.
$app->add(new \Slim\HttpCache\Cache('cache', 86400));

// Routes:
$app->get('/', function (Request $request, Response $response, array $args) {
    $response->getBody()->write('Hello, World!');

    return $response->withHeader('Content-type', 'application/json');
});

$app->get('/foo', function ($req, $res, $args) {
    $resWithEtag = $this->cache
    ->withEtag($res, 'abc')
    // ->withExpires($res, time() + 60)
    ;

    return $resWithEtag;
});

$app->run();

何か案は?

4

1 に答える 1

3

\Slim\HttpCache\Cache()クライアント側 (ブラウザ) キャッシュ用の HTTP Cache です。

最大 3 つのパラメータが必要です。

 * @param string $type           The cache type: "public" or "private"
 * @param int    $maxAge         The maximum age of client-side cache
 * @param bool   $mustRevalidate must-revalidate

対応する HTTP 応答ヘッダーを生成します。

サーバー側のキャッシュとは関係ありません。

于 2015-12-21T09:39:26.353 に答える