Skip to content

Commit

Permalink
get found from request context
Browse files Browse the repository at this point in the history
  • Loading branch information
sumandari committed Dec 19, 2024
1 parent 494d498 commit 601a579
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/flask_caching/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from flask import current_app
from flask import Flask
from flask import g
from flask import request
from flask import Response
from flask import url_for
Expand Down Expand Up @@ -414,10 +415,11 @@ def decorated_function(*args, **kwargs):
if found and self.app.debug:
logger.info(f"Cache used for key: {cache_key}")
if response_hit_indication:
g.flask_caching_hit_cache = found

def apply_caching(response):
if found:
response.headers["hit_cache"] = found
if g.flask_caching_hit_cache:
response.headers["hit_cache"] = g.flask_caching_hit_cache
return response

self.app.after_request_funcs[None].append(apply_caching)
Expand Down

0 comments on commit 601a579

Please sign in to comment.