Skip to content
Permalink
Browse files

Allow service workers and expire caching to be disabled

Add new keys to the global config to disable either or both of these
forms of caching. By default they are both enabled, but in a dev
environment they can be annoying.
  • Loading branch information...
lovett committed Jul 2, 2019
1 parent cc5023b commit 9fee0807aba8f9e975418a142537d4ab77079dae
Showing with 14 additions and 4 deletions.
  1. +1 −1 .pylintrc
  2. +8 −2 medley.py
  3. +3 −1 templates/base.jinja.html
  4. +2 −0 tools/negotiable.py
@@ -364,7 +364,7 @@ max-attributes=7
max-bool-expr=5

# Maximum number of branch for function / method body
max-branches=15
max-branches=20

# Maximum number of locals for function / method body
max-locals=20
@@ -37,6 +37,7 @@ def main():
cherrypy.config.update({
"app_root": app_root,
"cache_dir": "./cache",
"cache_static_assets": True,
"database_dir": "./db",
"engine.autoreload.on": False,
"local_maintenance": True,
@@ -52,6 +53,7 @@ def main():
"server_root": server_root,
"tools.conditional_auth.on": False,
"users": {},
"use_service_workers": True,
"tools.conditional_auth.whitelist": "",

# Jinja templating won't work unless tools.encode is off
@@ -149,10 +151,14 @@ def main():
"tools.gzip.mime_types": ["text/*", "application/*"],
"tools.staticdir.on": True,
"tools.staticdir.dir": os.path.realpath(static_path),
"tools.expires.on": True,
"tools.expires.secs": 86400 * 7
}

if cherrypy.config.get("cache_static_assets"):
app_config[static_url].update({
"tools.expires.on": True,
"tools.expires.secs": 86400 * 7
})

cherrypy.tree.mount(
app_module.Controller(),
app_path,
@@ -53,7 +53,7 @@ <h1>
{% endif %}
</h1>

<span class="message-holder focus-buffer-display"></span>
<span class="focus-buffer-display"></span>
</header>
{% endblock %}

@@ -63,6 +63,7 @@ <h1>
{{ macros.staticAsset('shared', 'js/medley.js') }}


{% if use_service_workers %}
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/worker.js').then(registration => {
@@ -72,6 +73,7 @@ <h1>
console.info('Service workers are not supported here.');
}
</script>
{% endif %}

{% block scripts %}{% endblock %}

@@ -189,6 +189,8 @@ def render_html(self, body):
if values["app_url"]:
values["app_url"] = values["app_url"].pop()

values["use_service_workers"] = cherrypy.config.get("service_workers")

content_type = "text/html;charset={}".format(self.charset)
cherrypy.response.headers["Content-Type"] = content_type

0 comments on commit 9fee080

Please sign in to comment.
You can’t perform that action at this time.