public static function instance($course, ?\context $context = null) {

        $courseid = $course;
        if (!is_scalar($courseid)) {
            $courseid = $course->id;
        }

        if (self::$cachedid === $courseid) {
            return self::$cachedinstance;
        }

        $cachedinstance = new \core_analytics\course($course, $context);
        self::$cachedinstance = $cachedinstance;
        self::$cachedid = (int)$courseid;
        return self::$cachedinstance;
    }