<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def purge(self, key, ttl):
 """ Remove all the items in the cache for the given key that are older than ttl seconds. If the key is not in the cache, raises a KeyError. """

        mors_to_purge = []
        now = time.time()
        with self._mor_lock:
            # Don't change the dict during iteration!
            # First collect the names of the Mors to remove...
            for name, mor in iteritems(self._mor[key]):
                age = now - mor['creation_time']
                if age > ttl:
                    mors_to_purge.append(name)

            # ...then actually remove the Mors from the cache.
            for name in mors_to_purge:
                del self._mor[key][name]