public function clear_indexes($invalid)
    {
        if (empty($invalid)) {
            return;
        }
        $this->get_index();
        foreach ($invalid as $collection => $key) {
            // Clear all indexes per collection
            if (isset($this->indexes[$collection])) {
                if ($key === true) {
                    foreach ($this->indexes[$collection] as $cache_key => $size) {
                        $cache_path = $this->get_path($cache_key, 'result');
                        $this->clear_cache($cache_path);
                        unset($this->indexes[$collection][$cache_key]);
                    }
                }
                // Clear a single index element by key
                else if ($key && isset($this->indexes[$collection][$key])) {
                    $cache_path = $this->get_path($key, 'result');
                    $this->clear_cache($cache_path);
                    unset($this->indexes[$collection][$key]);
                }
            }
        }
        $index_path = $this->get_path('index');
        $this->write_cache($index_path, $this->indexes);
    }