Explain how you would implement a caching mechanism for a web application in a way that works reliably at scale.