aboutsummaryrefslogtreecommitdiffstats
path: root/server.py
diff options
context:
space:
mode:
authormjfernez <mjfernez@gmail.com>2021-10-10 22:15:07 -0400
committermjfernez <mjfernez@gmail.com>2021-10-10 22:15:07 -0400
commit02a37ad308fbcc27a04787c84a76de7c2936a6d5 (patch)
treedf25089ab76cc0c3faa94e2990b600ea7568ab63 /server.py
parenta800163aeae0998fa49f011664f32a6c348db886 (diff)
downloadezcms-02a37ad308fbcc27a04787c84a76de7c2936a6d5.tar.gz
Caching support. Separate views.py in 2 files
This commit adds the Flask-Caching module to the software stack and enables the caching of views in a wide variety of ways, but implemented here to be simple to understand to someone new to the concept of caching (aka me). Various documentation and formatting was applied to all files. views.py internal functions (mostly related to filesystem operations of the server). have been moved into view_functions.py
Diffstat (limited to 'server.py')
-rw-r--r--server.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/server.py b/server.py
index 8937d4b..85ffad0 100644
--- a/server.py
+++ b/server.py
@@ -1,10 +1,20 @@
+"""
+server.py - sets up and runs the flask server
+"""
import os
from flask import Flask
from siteconfig import siteconfig
from flask_compress import Compress
+from flask_caching import Cache
app = Flask(__name__)
compress = Compress()
+cache = Cache(
+ config={
+ 'CACHE_TYPE': siteconfig.CACHE_TYPE,
+ 'CACHE_DEFAULT_TIMEOUT': siteconfig.CACHE_DEFAULT_TIMEOUT,
+ }
+)
from views import *
@@ -25,17 +35,22 @@ def setup():
else:
s = "./templates/site/"
top_dirs = [
- x for x in os.listdir(s) \
- if os.path.isdir(s + x) and not x.startswith(".")
+ x
+ for x in os.listdir(s)
+ if os.path.isdir(s + x) and not x.startswith(".")
]
app.config.update({'MAIN_SITE_DIRS': sorted(top_dirs)})
app.config.update({'DOMAIN': siteconfig.DOMAIN})
app.config.update({'HOME_TITLE': siteconfig.HOME_TITLE})
- app.config.update({'COMPRESS_MIMETYPES': siteconfig.COMPRESS_MIMETYPES})
+ app.config.update(
+ {'COMPRESS_MIMETYPES': siteconfig.COMPRESS_MIMETYPES}
+ )
+
# Setup needs to come first to be compatible with wsgi
setup()
if __name__ == "__main__":
compress.init_app(app)
+ cache.init_app(app)
app.run()