mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2024-11-26 02:30:21 -06:00
Prevent browsers caching responses. Fixes #1171
This commit is contained in:
parent
7a40171300
commit
2077bd5fdc
@ -29,6 +29,18 @@ class DataTypeJSONEncoder(json.JSONEncoder):
|
||||
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
def get_no_cache_header():
|
||||
"""
|
||||
Prevent browser from caching data every time an
|
||||
http request is made.
|
||||
Returns: headers
|
||||
"""
|
||||
headers = {}
|
||||
headers["Cache-Control"] = "no-cache, no-store, must-revalidate" # HTTP 1.1.
|
||||
headers["Pragma"] = "no-cache" # HTTP 1.0.
|
||||
headers["Expires"] = "0" # Proxies.
|
||||
return headers
|
||||
|
||||
|
||||
def make_json_response(
|
||||
success=1, errormsg='', info='', result=None, data=None, status=200
|
||||
@ -45,7 +57,8 @@ def make_json_response(
|
||||
return Response(
|
||||
response=json.dumps(doc, cls=DataTypeJSONEncoder),
|
||||
status=status,
|
||||
mimetype="application/json"
|
||||
mimetype="application/json",
|
||||
headers=get_no_cache_header()
|
||||
)
|
||||
|
||||
|
||||
@ -54,7 +67,8 @@ def make_response(response=None, status=200):
|
||||
return Response(
|
||||
response=json.dumps(response, cls=DataTypeJSONEncoder),
|
||||
status=status,
|
||||
mimetype="application/json"
|
||||
mimetype="application/json",
|
||||
headers=get_no_cache_header()
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user