public function doCache($sectionKey, &$section)
    {
        do_action("before_theme_do_cache", $sectionKey);

        $cacheKey = $this->getCacheKey($sectionKey, $section);

        # Get cache file absolute path
        $file = $this->getCacheFile($cacheKey);

        # Start buffering output
        ob_start();

        # Render the template
        $section->init();
        $section->render();

        $cacheConfig = $this->getConfig("cache");

        # Minify the output
        if ($cacheConfig["minify"]):
            $cache = str_replace(["  ", "\n", "\t"], ["", "", ""], ob_get_clean());
        else:
            $cache = ob_get_clean();
        endif;

        # Write output to memory or file
        if ($cacheConfig["type"] == "wp_cache"):
            wp_cache_add(basename($file), $cache, "sections_cache", $cacheConfig["lifetime"]);
        else:
            # Delete file if already exists
            if (file_exists($file)):
                unlink($file);
            endif;

            # Prevents creating empty cache file
            if (!empty($cache) || $cache != ""):
                file_put_contents($file, $cache);
            endif;
        endif;

        do_action("after_theme_do_cache", $cache);

        # Return output
        return $cache;
    }