mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Don't serve cache headers in debug or refresh modes
This commit is contained in:
parent
a8a293cd71
commit
e9fce44195
2 changed files with 8 additions and 5 deletions
|
|
@ -78,6 +78,7 @@ class BaseView(HTTPMethodView):
|
||||||
self.files = datasette.files
|
self.files = datasette.files
|
||||||
self.jinja = datasette.jinja
|
self.jinja = datasette.jinja
|
||||||
self.executor = datasette.executor
|
self.executor = datasette.executor
|
||||||
|
self.cache_headers = datasette.cache_headers
|
||||||
|
|
||||||
def redirect(self, request, path):
|
def redirect(self, request, path):
|
||||||
if request.query_string:
|
if request.query_string:
|
||||||
|
|
@ -183,9 +184,10 @@ class BaseView(HTTPMethodView):
|
||||||
**context,
|
**context,
|
||||||
)
|
)
|
||||||
# Set far-future cache expiry
|
# Set far-future cache expiry
|
||||||
r.headers['Cache-Control'] = 'max-age={}'.format(
|
if self.cache_headers:
|
||||||
365 * 24 * 60 * 60
|
r.headers['Cache-Control'] = 'max-age={}'.format(
|
||||||
)
|
365 * 24 * 60 * 60
|
||||||
|
)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -379,12 +381,13 @@ def resolve_db_name(files, db_name, **kwargs):
|
||||||
|
|
||||||
|
|
||||||
class Datasette:
|
class Datasette:
|
||||||
def __init__(self, files, num_threads=3):
|
def __init__(self, files, num_threads=3, cache_headers=True):
|
||||||
self.files = files
|
self.files = files
|
||||||
self.num_threads = num_threads
|
self.num_threads = num_threads
|
||||||
self.executor = futures.ThreadPoolExecutor(
|
self.executor = futures.ThreadPoolExecutor(
|
||||||
max_workers=num_threads
|
max_workers=num_threads
|
||||||
)
|
)
|
||||||
|
self.cache_headers = cache_headers
|
||||||
|
|
||||||
def app(self):
|
def app(self):
|
||||||
app = Sanic(__name__)
|
app = Sanic(__name__)
|
||||||
|
|
|
||||||
|
|
@ -29,5 +29,5 @@ def serve(files, host, port, debug, reload):
|
||||||
hupper.start_reloader('datasette.cli.serve')
|
hupper.start_reloader('datasette.cli.serve')
|
||||||
|
|
||||||
click.echo('Serve! files={} on port {}'.format(files, port))
|
click.echo('Serve! files={} on port {}'.format(files, port))
|
||||||
app = Datasette(files).app()
|
app = Datasette(files, cache_headers=not debug and not reload).app()
|
||||||
app.run(host=host, port=port, debug=debug)
|
app.run(host=host, port=port, debug=debug)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue