Skip to content

Commit

Permalink
deposit: force no caching in the response headers
Browse files Browse the repository at this point in the history
Co-authored-by: jrcastro2 <[email protected]>

closes CERNDocumentServer/cds-rdm#302
  • Loading branch information
zzacharo committed Jan 20, 2025
1 parent 13967bd commit ac4c2b3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
21 changes: 21 additions & 0 deletions invenio_app_rdm/records_ui/views/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,3 +403,24 @@ def view(**kwargs):
return view

return decorator


def no_cache_response(f):
"""Add appropriate response headers to force no caching.
This decorator is used to prevent caching of the response in the browser. This is needed
in the deposit form as we initialize the form with the record metadata included in the html page
and we don't want the browser to cache this page so that the user always gets the latest version of the record.
"""

@wraps(f)
def view(*args, **kwargs):
response = make_response(f(*args, **kwargs))

response.cache_control.no_cache = True
response.cache_control.no_store = True
response.cache_control.must_revalidate = True

return response

return view
3 changes: 3 additions & 0 deletions invenio_app_rdm/records_ui/views/deposits.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

from ..utils import set_default_value
from .decorators import (
no_cache_response,
pass_draft,
pass_draft_community,
pass_draft_files,
Expand Down Expand Up @@ -424,6 +425,7 @@ def new_record():
# Views
#
@login_required
@no_cache_response
@pass_draft_community
def deposit_create(community=None):
"""Create a new deposit."""
Expand Down Expand Up @@ -475,6 +477,7 @@ def deposit_create(community=None):
@secret_link_or_login_required()
@pass_draft(expand=True)
@pass_draft_files
@no_cache_response
def deposit_edit(pid_value, draft=None, draft_files=None, files_locked=True):
"""Edit an existing deposit."""
# don't show draft's deposit form if the user can't edit it
Expand Down

0 comments on commit ac4c2b3

Please sign in to comment.