Fixed undefined variable issues in cache logic.