有人能解决CodeIgniter中该高速缓存问题吗?或者如何在CodeIgniter中设置缓存?

jm81lzqq  于 2023-08-01  发布在  其他
关注(0)|答案(1)|浏览(94)

我在我的索引函数中添加了这个

$this->output->set_cache_header('Cache-Control: no-cache, must-revalidate');

字符串
但是发生了一个错误。

An uncaught Exception was encountered
Type: ArgumentCountError

Message: Too few arguments to function CI_Output::set_cache_header(), 1 passed in C:\xampp\htdocs\lsc\application\controllers\Home.php on line 24 and exactly 2 expected

Filename: C:\xampp\htdocs\lsc\system\core\Output.php

Line Number: 792

Backtrace:

File: C:\xampp\htdocs\lsc\application\controllers\Home.php
Line: 24
Function: set_cache_header

File: C:\xampp\htdocs\lsc\index.php
Line: 315
Function: require_once


有人能告诉我怎么用这个吗?
我想为我的网站设置该高速缓存,并告诉我如何在网站中使用缓存

kcugc4gi

kcugc4gi1#

如果你想阻止缓存,可以使用set_header函数:

$this->output->set_header('Cache-Control: no-cache, must-revalidate', TRUE);

字符串
如果要启用缓存,请将两个timestamp值传递给函数set_cache_header

$this->output->set_header(time(), strtotime('+1 days'));
/**
     * Set Cache Header
     *
     * Set the HTTP headers to match the server-side file cache settings
     * in order to reduce bandwidth.
     *
     * @param   int $last_modified  Timestamp of when the page was last modified
     * @param   int $expiration Timestamp of when should the requested page expire from cache
     * @return  void
     */
    public function set_cache_header($last_modified, $expiration)

相关问题