<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_all(self, seq_set: SequenceSet) \ -> Sequence[Tuple[int, CachedMessage]]: """Return the cached messages, and their sequence numbers, for the given sequence set. Args: seq_set: The message sequence set. """

        if seq_set.uid:
            all_uids = seq_set.flatten(self.max_uid) & self._uids
            return [(seq, self._cache[uid])
                    for seq, uid in enumerate(self._sorted, 1)
                    if uid in all_uids]
        else:
            all_seqs = seq_set.flatten(self.exists)
            return [(seq, self._cache[uid])
                    for seq, uid in enumerate(self._sorted, 1)
                    if seq in all_seqs]