我想在响应头Cache-control: max-age=1800
的JSON。我使用静态文件缓存。在本地DDEV这工程开箱即用罚款。对于Mittwald - Apache服务器-我添加了.htaccess规则,如手册中所述[1]。
字体:
jsonFeed = PAGE
jsonFeed {
typeNum = 1234
config {
disableAllHeaderCode = 1
disableCharsetHeader = 1
disablePrefixComment = 1
additionalHeaders.10.header = Content-type: application/json
admPanel = 0
debug = 0
no_cache = 0
# this is also set in .htaccess
cache_period = 1800
sendCacheHeaders = 1
}
10 = USER
10 {
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
vendorName = Bliep
extensionName = Newsfeed
pluginName = FeedList
action = list
}
}
我在.htaccess中添加了额外的内容
<FilesMatch "\.json$">
ForceType application/json
Header set Cache-Control "max-age=1800, public"
</FilesMatch>
和
ExpiresByType application/json "access plus 1800 seconds"
在第一次命中时,我确实得到了带有X-Sfc-State: TYPO3 - add to cache
的响应头Cache-control: max-age=1800
在第二次+命中时,它总是更改为Cache-control: max-age=0
,实际上是X-Sfc-State: StaticFileCache - via htaccess
我没有登录在后端,它也发生在另一个浏览器.正常的页面得到正确的缓存控制.在本地DDEV Ngninx我得到Cache-control: max-age=1800
为https://bla.com/feed.json
feed.json被Map到routeEnhancer中:feed.json: 1234
有什么线索能引起这个吗?
[1][https://docs.typo3.org/p/lochmueller/staticfilecache/main/en-us/Configuration/Htaccess.html](https://docs.typo3.org/p/lochmueller/staticfilecache/main/en-us/Configuration/Htaccess.html)。
1条答案
按热度按时间ddarikpa1#
静态文件chache的工作原理是创建“静态文件”
在你的第一个请求中没有文件.所以它apache将重定向到index.php,然后PHP将生成文件(写入磁盘)并直接交付它.所以这解释了为什么第一个请求正确地交付数据.
对于第二个请求,文件在那里.它直接由web服务器传递.所以你的.htaccess修改似乎没有达到预期的效果.
所以问题变成了为什么Apache不执行FileMatch/header规则。
可能发生这种情况的原因有很多:
一个测试你的规则是否被触发的好方法是使用一个自定义头(通常以“x-”开头,例如“x-header-add:works”)