fix: eliminate stale cache bug caused by multi-worker SimpleCache
Browse filesRoot cause: gunicorn --workers 2 gives each worker an independent
SimpleCache. A cache.delete_memoized() call in Worker 1 has no effect
on Worker 2's cache, so Worker 2 can serve stale data for up to the
cache timeout (180s for employees/periods, 300s for settings).
Fix 1: reduce to --workers 1
- SimpleCache invalidation now always works (single process)
- Solver still works via background daemon thread (releases GIL)
- Sufficient for single-restaurant low-concurrency usage
Fix 2: save_app_setting now also invalidates get_all_app_settings
- Previously only invalidated the specific key's cache
- get_all_app_settings() could return stale data after individual
save_app_setting() calls
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Dockerfile +1 -1
- db/repositories.py +1 -0
|
@@ -14,4 +14,4 @@ COPY . .
|
|
| 14 |
ENV PORT=8080
|
| 15 |
EXPOSE 8080
|
| 16 |
|
| 17 |
-
CMD ["sh", "-c", "gunicorn 'web_app:create_app()' --bind 0.0.0.0:$PORT --workers
|
|
|
|
| 14 |
ENV PORT=8080
|
| 15 |
EXPOSE 8080
|
| 16 |
|
| 17 |
+
CMD ["sh", "-c", "gunicorn 'web_app:create_app()' --bind 0.0.0.0:$PORT --workers 1 --timeout 120"]
|
|
@@ -466,6 +466,7 @@ def save_app_setting(key: str, value: str):
|
|
| 466 |
conn.commit()
|
| 467 |
conn.close()
|
| 468 |
cache.delete_memoized(get_app_setting, key)
|
|
|
|
| 469 |
|
| 470 |
|
| 471 |
@cache.memoize(timeout=300)
|
|
|
|
| 466 |
conn.commit()
|
| 467 |
conn.close()
|
| 468 |
cache.delete_memoized(get_app_setting, key)
|
| 469 |
+
cache.delete_memoized(get_all_app_settings) # get_all_app_settings も無効化
|
| 470 |
|
| 471 |
|
| 472 |
@cache.memoize(timeout=300)
|