split caching into types

This commit is contained in:
lelo 2025-03-31 09:11:37 +00:00
parent f57db40e4f
commit 71c0585380
2 changed files with 21 additions and 1 deletions

5
.gitignore vendored
View File

@ -1,5 +1,10 @@
/venv /venv
/filecache /filecache
/filecache_audio
/filecache_image
/filecache_video
/filecache_other
/instance
/__pycache__ /__pycache__
/access_log.db /access_log.db
/folder_config.json /folder_config.json

17
app.py
View File

@ -20,7 +20,10 @@ from werkzeug.middleware.proxy_fix import ProxyFix
import auth import auth
import analytics as a 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 = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1) 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) # Check cache first (using diskcache)
response = None 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) cached = cache.get(subpath)
if cached: if cached:
cached_file_bytes, mime = cached cached_file_bytes, mime = cached