protected function get_purpose_for_expiry(expired_context $expiredcontext) : purpose {
        $context = context_helper::instance_by_id($expiredcontext->get('contextid'));

        if (empty($this->purposemap[$context->id])) {
            $purpose = api::get_effective_context_purpose($context);
            $this->purposemap[$context->id] = $purpose->get('id');

            if (empty($this->purposes[$purpose->get('id')])) {
                $this->purposes[$purpose->get('id')] = $purpose;
            }
        }

        return $this->purposes[$this->purposemap[$context->id]];
    }