Skip to content
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

views: disable caching on deposit edit #2950

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions invenio_app_rdm/records_ui/views/deposits.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from copy import deepcopy

from flask import current_app, g, redirect
from flask import current_app, g, make_response, redirect
from flask_login import login_required
from invenio_communities.errors import CommunityDeletedError
from invenio_communities.proxies import current_communities
Expand Down Expand Up @@ -504,7 +504,7 @@ def deposit_edit(pid_value, draft=None, draft_files=None, files_locked=True):
if doi_provider_config:
doi_provider_config[0]["default_selected"] = "no"

return render_community_theme_template(
html_content = render_community_theme_template(
current_app.config["APP_RDM_DEPOSIT_FORM_TEMPLATE"],
theme=community_theme,
forms_config=form_config,
Expand All @@ -524,6 +524,15 @@ def deposit_edit(pid_value, draft=None, draft_files=None, files_locked=True):
]
),
)
# Wrap the HTML string in a response object
response = make_response(html_content)

# Add cache-control headers to the response
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "0"
Comment on lines +531 to +533
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Flask responses have some fancy APIs, that allow you to do something like:

Suggested change
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "0"
response.cache_control.no_cache = True
response.cache_control.no_store = True
response.cache_control.must_revalidate = True
# Not 100% sure about these two
response.pragma = "no-cache"
response.expires = "0"


return response


def community_upload(pid_value):
Expand Down