File tree Expand file tree Collapse file tree 3 files changed +15
-4
lines changed
apisix/plugins/proxy-cache Expand file tree Collapse file tree 3 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -52,14 +52,17 @@ function _M:get(key)
5252 end
5353
5454 -- If the key does not exist or has expired, then res_json will be nil.
55- local res_json , err = self .dict :get (key )
55+ local res_json , err , stale = self .dict :get_stale (key )
5656 if not res_json then
5757 if not err then
5858 return nil , " not found"
5959 else
6060 return nil , err
6161 end
6262 end
63+ if stale then
64+ return nil , " expired"
65+ end
6366
6467 local res_obj , err = core .json .decode (res_json )
6568 if not res_obj then
Original file line number Diff line number Diff line change @@ -213,11 +213,19 @@ function _M.access(conf, ctx)
213213 end
214214
215215 if err then
216- core .response .set_header (" Apisix-Cache-Status" , " MISS" )
217- if err ~= " not found" then
216+ if err == " expired" then
217+ core .response .set_header (" Apisix-Cache-Status" , " EXPIRED" )
218+
219+ elseif err ~= " not found" then
220+ core .response .set_header (" Apisix-Cache-Status" , " MISS" )
218221 core .log .error (" failed to get from cache, err: " , err )
222+
219223 elseif conf .cache_control and cc [" only-if-cached" ] then
224+ core .response .set_header (" Apisix-Cache-Status" , " MISS" )
220225 return 504
226+
227+ else
228+ core .response .set_header (" Apisix-Cache-Status" , " MISS" )
221229 end
222230 return
223231 end
Original file line number Diff line number Diff line change @@ -506,7 +506,7 @@ GET /hello
506506--- response_body chop
507507hello world!
508508--- response_headers
509- Apisix-Cache-Status: MISS
509+ Apisix-Cache-Status: EXPIRED
510510
511511
512512
You can’t perform that action at this time.
0 commit comments