-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PoC with response and API caching #372
base: development
Are you sure you want to change the base?
Conversation
42111c9
to
00d8cbc
Compare
549043c
to
175d723
Compare
175d723
to
3e922b4
Compare
Perhaps it is already in your TODOs, a note is that I encountered an error of flask_session version is outdated in the requirement.txt. Thus, importing flask_session.filesystem reported an error. Upgrading flask_session to 0.8.0 resolved the issue. |
Yeah, I already upgraded the versions in development. Will merge with this branch soon. |
def make_key(api_key: Optional[str] = None) -> str: | ||
"""Generate a cache key based on the request and authentication status. | ||
|
||
:param api_key: Optional custom key indentifying API endpoint. If None, defaults to request endpoint and method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:param api_key: Optional custom key indentifying API endpoint. If None, defaults to request endpoint and method | |
:param api_key: Optional custom key identifying API endpoint. If None, defaults to request endpoint and method |
if authenticated(): | ||
user = g.get('user') | ||
is_development = app.config.get("YODA_ENVIRONMENT") == "development" | ||
user_identifier = user if is_development else hashlib.shake_256(user.encode("utf-8")).hexdigest(20) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In make_key and clear_view_cache_keys, you both used user = g.get, is_dev =... and user identifier. I would suggest to have a single helper function to put them together, like:
def get_user_identifier():
user = g.get('user')
if not user:
return "unauthenticated"
is_development = app.config.get("YODA_ENVIRONMENT") == "development"
return user if is_development else hashlib.shake_256(...).hexdigest(20)
Then you can just call them inside each func.
This PR adds caching for Flask responses to avoid re-rendering templates, improving performance. It introduces API caching for a limited set of endpoints with defined timeouts.
Additionally, some API calls have been moved to the client side to leverage the template cache, further enhancing efficiency. Certain API calls will trigger cache clearing to ensure users receive up-to-date information.