You cached something in a module-level dictionary. It works on your laptop and behaves oddly in production. What is different?
Production runs several worker processes, and each has its own interpreter, its own imported modules and therefore its own copy of that dictionary. Requests land on whichever worker is free, so a write in one is invisible to the others and every restart discards the lot. Use this wsgi asgi answer to show the decision, trade-off, and evidence rather than a memorised definition.