split caching into types
This commit is contained in:
parent
f57db40e4f
commit
71c0585380
5
.gitignore
vendored
5
.gitignore
vendored
@ -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
17
app.py
@ -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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user