public function set_mode_mappings(array $modemappings) {
        $mappings = array(
            cache_store::MODE_APPLICATION => array(),
            cache_store::MODE_SESSION => array(),
            cache_store::MODE_REQUEST => array(),
        );
        foreach ($modemappings as $mode => $stores) {
            if (!array_key_exists($mode, $mappings)) {
                throw new cache_exception('The cache mode for the new mapping does not exist');
            }
            $sort = 0;
            foreach ($stores as $store) {
                if (!array_key_exists($store, $this->configstores)) {
                    throw new cache_exception('The instance name for the new mapping does not exist');
                }
                if (array_key_exists($store, $mappings[$mode])) {
                    throw new cache_exception('This cache mapping already exists');
                }
                $mappings[$mode][] = array(
                    'store' => $store,
                    'mode' => $mode,
                    'sort' => $sort++
                );
            }
        }
        $this->configmodemappings = array_merge(
            $mappings[cache_store::MODE_APPLICATION],
            $mappings[cache_store::MODE_SESSION],
            $mappings[cache_store::MODE_REQUEST]
        );

        $this->config_save();
        return true;
    }