Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ac4c2b3

Browse files
committedJan 20, 2025
deposit: force no caching in the response headers
Co-authored-by: jrcastro2 <jrcastro9515@gmail.com> closes CERNDocumentServer/cds-rdm#302
1 parent 13967bd commit ac4c2b3

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
 

‎invenio_app_rdm/records_ui/views/decorators.py

+21
Original file line numberDiff line numberDiff line change
@@ -403,3 +403,24 @@ def view(**kwargs):
403403
return view
404404

405405
return decorator
406+
407+
408+
def no_cache_response(f):
409+
"""Add appropriate response headers to force no caching.
410+
411+
This decorator is used to prevent caching of the response in the browser. This is needed
412+
in the deposit form as we initialize the form with the record metadata included in the html page
413+
and we don't want the browser to cache this page so that the user always gets the latest version of the record.
414+
"""
415+
416+
@wraps(f)
417+
def view(*args, **kwargs):
418+
response = make_response(f(*args, **kwargs))
419+
420+
response.cache_control.no_cache = True
421+
response.cache_control.no_store = True
422+
response.cache_control.must_revalidate = True
423+
424+
return response
425+
426+
return view

‎invenio_app_rdm/records_ui/views/deposits.py

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
from ..utils import set_default_value
3939
from .decorators import (
40+
no_cache_response,
4041
pass_draft,
4142
pass_draft_community,
4243
pass_draft_files,
@@ -424,6 +425,7 @@ def new_record():
424425
# Views
425426
#
426427
@login_required
428+
@no_cache_response
427429
@pass_draft_community
428430
def deposit_create(community=None):
429431
"""Create a new deposit."""
@@ -475,6 +477,7 @@ def deposit_create(community=None):
475477
@secret_link_or_login_required()
476478
@pass_draft(expand=True)
477479
@pass_draft_files
480+
@no_cache_response
478481
def deposit_edit(pid_value, draft=None, draft_files=None, files_locked=True):
479482
"""Edit an existing deposit."""
480483
# don't show draft's deposit form if the user can't edit it

0 commit comments

Comments
 (0)
Please sign in to comment.