| 1 |
# Test application for functional testing of flask-caching |
| 2 |
# |
| 3 |
# Copyright (C) 2022 Emanuele Rocca <[email protected]> |
| 4 |
# |
| 5 |
# This program is free software: you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation, either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# This program is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
from flask import Flask |
| 19 |
from flask_caching import Cache |
| 20 |
|
| 21 |
config = { |
| 22 |
"CACHE_TYPE": "SimpleCache", |
| 23 |
"CACHE_DEFAULT_TIMEOUT": 300 |
| 24 |
} |
| 25 |
app = Flask(__name__) |
| 26 |
app.config.from_mapping(config) |
| 27 |
cache = Cache(app) |
| 28 |
|
| 29 |
counter = 0 |
| 30 |
|
| 31 |
@app.route("/") |
| 32 |
@cache.cached(timeout=10) |
| 33 |
def index(): |
| 34 |
global counter |
| 35 |
counter += 1 |
| 36 |
return f"counter={counter}" |
| 37 |
|
| 38 |
if __name__ == "__main__": |
| 39 |
app.run() |