<commit_before><?php
namespace TypiCMS\Modules\Core\Http\Middleware;

use Closure;
use Exception;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\File;
use Illuminate\View\View;
use Pages;

class PublicCache
{

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        // dd($request);
        $response = $next($request);

        /**
         * If page is not cacheable, don’t generate static html.
         */
        if (isset($response->original->page) && $response->original->page->no_cache) {
            return $response;
        }

        // HTML cache
        if (
            !$response->isRedirection() &&
            $request->isMethod('get') &&
            !Auth::check() &&
            $this->queryStringIsEmptyOrOnlyPage($request) &&
            !config('app.debug') &&
            config('typicms.html_cache')
        ) {
            $directory = public_path() . '/html' . $request->getPathInfo();
            if (!File::isDirectory($directory)) {
                File::makeDirectory($directory, 0777, true);
            }
            File::put($directory . '/index' . $request->getQueryString() . '.html', $response->content());
        }

        return $response;
    }
<commit_msg>comment<commit_after><?php
namespace TypiCMS\Modules\Core\Http\Middleware;

use Closure;
use Exception;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\File;
use Illuminate\View\View;
use Pages;

class PublicCache
{

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $response = $next($request);

        /**
         * If page is not cacheable, don’t generate static html.
         */
        if (isset($response->original->page) && $response->original->page->no_cache) {
            return $response;
        }

        // HTML cache
        if (
            !$response->isRedirection() &&
            $request->isMethod('get') &&
            !Auth::check() &&
            $this->queryStringIsEmptyOrOnlyPage($request) &&
            !config('app.debug') &&
            config('typicms.html_cache')
        ) {
            $directory = public_path() . '/html' . $request->getPathInfo();
            if (!File::isDirectory($directory)) {
                File::makeDirectory($directory, 0777, true);
            }
            File::put($directory . '/index' . $request->getQueryString() . '.html', $response->content());
        }

        return $response;
    }

{'fraction_non_alphanumeric': 0.1490367139222101, 'fraction_numerical': 0.0029080334423845873, 'mean_word_length': 2.020856201975851, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1669546', 'n_tokens_mistral': 793, 'n_tokens_neox': 787, 'n_words': 151}