public static function get($id, $strictness = MUST_EXIST, $alwaysreturnhidden = false, $user = null) {
        if (!$id) {
            // Top-level category.
            if ($alwaysreturnhidden || self::top()->is_uservisible()) {
                return self::top();
            }
            if ($strictness == MUST_EXIST) {
                throw new moodle_exception('cannotviewcategory');
            }
            return null;
        }

        // Try to get category from cache or retrieve from the DB.
        $coursecatrecordcache = cache::make('core', 'coursecatrecords');
        $coursecat = $coursecatrecordcache->get($id);
        if ($coursecat === false) {
            if ($records = self::get_records('cc.id = :id', array('id' => $id))) {
                $record = reset($records);
                $coursecat = new self($record);
                // Store in cache.
                $coursecatrecordcache->set($id, $coursecat);
            }
        }

        if (!$coursecat) {
            // Course category not found.
            if ($strictness == MUST_EXIST) {
                throw new moodle_exception('unknowncategory');
            }
            $coursecat = null;
        } else if (!$alwaysreturnhidden && !$coursecat->is_uservisible($user)) {
            // Course category is found but user can not access it.
            if ($strictness == MUST_EXIST) {
                throw new moodle_exception('cannotviewcategory');
            }
            $coursecat = null;
        }
        return $coursecat;
    }