moved check for valid cache