uwsgi如何缓存non-text/html内容?
How does uwsgi cache non-text/html content?
有人可以解释一下 the uwsgi docs 中的以下代码片段是如何工作的吗?
cache2 = name=mycache,items=100
; load the mime types engine
mime-file = /etc/mime.types
; at each request starting with /img check it in the cache (use mime types engine for the content type)
route = ^/img/(.+) cache:key=/img/,name=mycache,mime=1
; at each request ending with .css check it in the cache
route = \.css$ cache:key=${REQUEST_URI},name=mycache,content_type=text/css
; fallback to text/html all of the others request
route = .* cache:key=${REQUEST_URI},name=mycache
; store each successful request (200 http status code) in the 'mycache' cache using the REQUEST_URI as key
route = .* cachestore:key=${REQUEST_URI},name=mycache
由于${REQUEST_URI}是用来存储缓存中的所有内容,而只有${REQUEST_URI}的一部分用来检查缓存中的图片,这应该怎么办工作?我确实输出 ${REQUEST_URI} 和 log: 路由目标,它等于从第一个/每次开始的完整请求。
我的设置中类似的东西不起作用(我使用 /usr/local/etc/nginx/mime.types 作为 mime 类型文件)。
谢谢,
吨。
仔细看这一行:
route = ^/img/(.+) cache:key=/img/,name=mycache,mime=1
它将捕获所有对 /img/
目录中文件的请求,将其相对于 /img/
的路径保存在变量 </code> 中。现在它向缓存询问密钥 <code>/img/
,因此它将在保存路径的开头粘贴 /img/
。
对于文件/img/my_logo.png
,它会将"my_logo.png"保存在</code>变量中,然后它会在保存路径的开头粘贴“/img/”,所以最后,它将查询 <code>/img/my_logo.png
.
基本上,它重新创建了 REQUEST_URI
。因此,如果它对您不起作用,请确保您在正则表达式和缓存键中使用相同的基本目录名称。
有人可以解释一下 the uwsgi docs 中的以下代码片段是如何工作的吗?
cache2 = name=mycache,items=100
; load the mime types engine
mime-file = /etc/mime.types
; at each request starting with /img check it in the cache (use mime types engine for the content type)
route = ^/img/(.+) cache:key=/img/,name=mycache,mime=1
; at each request ending with .css check it in the cache
route = \.css$ cache:key=${REQUEST_URI},name=mycache,content_type=text/css
; fallback to text/html all of the others request
route = .* cache:key=${REQUEST_URI},name=mycache
; store each successful request (200 http status code) in the 'mycache' cache using the REQUEST_URI as key
route = .* cachestore:key=${REQUEST_URI},name=mycache
由于${REQUEST_URI}是用来存储缓存中的所有内容,而只有${REQUEST_URI}的一部分用来检查缓存中的图片,这应该怎么办工作?我确实输出 ${REQUEST_URI} 和 log: 路由目标,它等于从第一个/每次开始的完整请求。
我的设置中类似的东西不起作用(我使用 /usr/local/etc/nginx/mime.types 作为 mime 类型文件)。
谢谢, 吨。
仔细看这一行:
route = ^/img/(.+) cache:key=/img/,name=mycache,mime=1
它将捕获所有对 /img/
目录中文件的请求,将其相对于 /img/
的路径保存在变量 </code> 中。现在它向缓存询问密钥 <code>/img/
,因此它将在保存路径的开头粘贴 /img/
。
对于文件/img/my_logo.png
,它会将"my_logo.png"保存在</code>变量中,然后它会在保存路径的开头粘贴“/img/”,所以最后,它将查询 <code>/img/my_logo.png
.
基本上,它重新创建了 REQUEST_URI
。因此,如果它对您不起作用,请确保您在正则表达式和缓存键中使用相同的基本目录名称。