首页 > 解决方案 > 如何在 PHP 中控制缓存

问题描述

我正在开发基于 Php 的电子商务网站,但我没有使用 Apache 作为服务器,而是创建了自己的自定义服务器脚本,如下所示:

我有 Index.php 我把所有路由放在哪里,它工作正常但是当我尝试实现缓存控制时,它不会适用。

这是目录结构:

--src
  --public
    --index.php
    --.htaccess
  --views

我认为我的 .htaccess 文件无法正常工作,没有图像、css、js 缓存到内存中

这是 .htaccess 代码

# Leverage Browser Caching
<IfModule mod_headers.c>
  Header set Connection keep-alive
  <filesmatch "\.(ico|flv|jpg|jpeg|png|gif|css|swf)$">
  Header set Cache-Control "max-age=2678400, public"
  </filesmatch>
  <filesmatch "\.(html|htm)$">
  Header set Cache-Control "max-age=7200, private, must-revalidate"
  </filesmatch>
  <filesmatch "\.(pdf)$">
  Header set Cache-Control "max-age=86400, public"
  </filesmatch>
  <filesmatch "\.(js)$">
  Header set Cache-Control "max-age=2678400, private"
  </filesmatch>
</IfModule>

标签: javascriptphpcachingbrowser-cachecache-control

解决方案


推荐阅读