Commit 83dfe548 authored by Ziirish's avatar Ziirish

fix some cmient-side caching issues (see #316)

parent 383057ca
Pipeline #1678 passed with stages
in 10 minutes and 37 seconds
......@@ -13,7 +13,7 @@ import sys
import uuid
import hashlib
from flask import Blueprint, Response, request, current_app, session, abort
from flask import Blueprint, Response, request, current_app, session, abort, g
from flask_restplus import Api as ApiPlus
from flask_login import current_user
from importlib import import_module
......@@ -31,7 +31,8 @@ EXEMPT_METHODS = set(['OPTIONS'])
def force_refresh():
return request.headers.get('X-No-Cache', False) is not False
return request.headers.get('X-No-Cache', False) is not False or \
getattr(g, 'DONOTCACHE', False)
def cache_key():
......
......@@ -16,7 +16,7 @@ from ..exceptions import BUIserverException
from ..decorators import browser_cache
from ..filter import mask
from flask import current_app
from flask import current_app, g
from flask_login import current_user
bui = current_app # type: BUIServer
......@@ -505,6 +505,8 @@ class ClientsStats(Resource):
self.abort(500, str(exp))
tmp_client['labels'] = labels
ret.append(tmp_client)
if tmp_client['state'] != 'idle':
g.DONOTCACHE = True
return ret
......
......@@ -9,7 +9,7 @@ from ..ext.cache import cache
from ..decorators import browser_cache
from ..exceptions import BUIserverException
from flask import current_app
from flask import current_app, g
from flask_login import current_user
bui = current_app # type: BUIServer
......@@ -76,6 +76,7 @@ class ServersStats(Resource):
alive = bui.client.servers[serv].ping()
except BUIserverException:
alive = False
g.DONOTCACHE = True
try:
clients = bui.client.servers[serv].get_all_clients(serv)
......
......@@ -10,6 +10,7 @@
import time
import datetime
from flask import g
from functools import wraps
......@@ -41,7 +42,10 @@ def browser_cache(expires=None):
headers['Last-Modified'] = format_date_time(time.mktime(now.timetuple()))
if expires is None:
failure = code - 200 >= 100 # this is not a successful answer
do_not_cache = getattr(g, 'DONOTCACHE', False)
if expires is None or failure or do_not_cache:
headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0'
else:
headers['Cache-Control'] = 'private, max-age={}'.format(expires)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment