def METHOD_NAME(
    self, query: PostgresQuery, prep: Prepare, name: bytes
) -> Optional[Key]:
    """Handle 'query' for possible addition to the cache.
    If a new entry has been added, return its key. Return None otherwise
    (meaning the query is already in cache or cache is not enabled).
    """
    # don't do anything if prepared statements are disabled
    if self.prepare_threshold is None:
        return None
    key = self.key(query)
    if key in self._counts:
        if prep is Prepare.SHOULD:
            del self._counts[key]
            self._names[key] = name
        else:
            self._counts[key] += 1
            self._counts.move_to_end(key)
        return None
    elif key in self._names:
        self._names.move_to_end(key)
        return None
    else:
        if prep is Prepare.SHOULD:
            self._names[key] = name
        else:
            self._counts[key] = 1
        return key