no_cache
FunctionPrivateDecoratorSource
@no_cache
def func(): ...
A deocrator adding no_cache
property to the flask
services.
This decorator will mark the response of a service by no_cache
. It is useful when the
same value needs to be triggered for multiple times. For example, in some cases, users
may need to click a button to download a file. If no_cache
is not configured, clicking
the button for the second time will not trigger any events unless the file to be served
is changed.
In other words, this decorator is used for disabling the cache for some specific services.
Arguments
No argument is needed.
Examples
Decorate a file event
- Codes
- Results
import io
import flask
from dash_file_cache.utilities import no_cache
app = flask.Flask("demo")
@no_cache
@app.route("/")
def index():
return flask.send_file(
io.BytesIO("test file".encode()),
mimetype="text/plain",
as_attachment=True,
download_name="test.txt",
)
if __name__ == "__main__":
app.run()
A file named text.txt
will be downloaded, the file content is
test file