Thread-safe MySQL caching