diff --git a/.gitignore b/.gitignore index 56465c8..81f3168 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,10 @@ /venv /filecache +/filecache_audio +/filecache_image +/filecache_video +/filecache_other +/instance /__pycache__ /access_log.db /folder_config.json diff --git a/app.py b/app.py index dbf3015..e0b8e98 100755 --- a/app.py +++ b/app.py @@ -20,7 +20,10 @@ from werkzeug.middleware.proxy_fix import ProxyFix import auth import analytics as a -cache = diskcache.Cache('./filecache', size_limit= 48 * 1024**3) # 48 GB limit +cache_audio = diskcache.Cache('./filecache_audio', size_limit= 48 * 1024**3) # 48 GB limit +cache_image = diskcache.Cache('./filecache_image', size_limit= 48 * 1024**3) # 48 GB limit +cache_video = diskcache.Cache('./filecache_video', size_limit= 48 * 1024**3) # 48 GB limit +cache_other = diskcache.Cache('./filecache_other', size_limit= 48 * 1024**3) # 48 GB limit app = Flask(__name__) app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1) @@ -212,6 +215,18 @@ def serve_file(subpath): # Check cache first (using diskcache) response = None + + # determine the cache to use based on the file type + if mime and mime.startswith('audio/'): + cache = cache_audio + elif mime and mime.startswith('image/'): + cache = cache_image + elif mime and mime.startswith('video/'): + cache = cache_video + else: + cache = cache_other + + # Check if the file is already cached cached = cache.get(subpath) if cached: cached_file_bytes, mime = cached