Skip to content

Commit

Permalink
Allow service workers and expire caching to be disabled
Browse files Browse the repository at this point in the history
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 9fee080
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions medley.py
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion templates/base.jinja.html
Expand Up @@ -53,7 +53,7 @@ <h1>
{% endif %}
</h1>

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

Expand All @@ -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 => {
Expand All @@ -72,6 +73,7 @@ <h1>
console.info('Service workers are not supported here.');
}
</script>
{% endif %}

{% block scripts %}{% endblock %}

Expand Down
2 changes: 2 additions & 0 deletions tools/negotiable.py
Expand Up @@ -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

Expand Down

0 comments on commit 9fee080

Please sign in to comment.