protected static function locate_definitions($coreonly = false) {
        global $CFG;

        $files = array();
        if (file_exists($CFG->dirroot.'/lib/db/caches.php')) {
            $files['core'] = $CFG->dirroot.'/lib/db/caches.php';
        }

        if (!$coreonly) {
            $plugintypes = core_component::get_plugin_types();
            foreach ($plugintypes as $type => $location) {
                $plugins = core_component::get_plugin_list_with_file($type, 'db/caches.php');
                foreach ($plugins as $plugin => $filepath) {
                    $component = clean_param($type.'_'.$plugin, PARAM_COMPONENT); // Standardised plugin name.
                    $files[$component] = $filepath;
                }
            }
        }

        $definitions = array();
        foreach ($files as $component => $file) {
            $filedefs = self::load_caches_file($file);
            foreach ($filedefs as $area => $definition) {
                $area = clean_param($area, PARAM_AREA);
                $id = $component.'/'.$area;
                $definition['component'] = $component;
                $definition['area'] = $area;
                if (array_key_exists($id, $definitions)) {
                    debugging('Error: duplicate cache definition found with id: '.$id, DEBUG_DEVELOPER);
                    continue;
                }
                $definitions[$id] = $definition;
            }
        }

        return $definitions;
    }