Fix thread local cache bug