<commit_before><?php
namespace Psr7Middlewares\Utils;

use RuntimeException;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;

/**
 * Utilities used by router middlewares
 */
trait CacheTrait
{
    /**
     * Check whether the response can be cached or not
     *
     * @param ServerRequestInterface $request
     * @param ResponseInterface      $response
     *
     * @return boolean
     */
    protected static function isCacheable(ServerRequestInterface $request, ResponseInterface $response)
    {
        if ($request->getMethod() !== 'GET') {
            return false;
        }

        if (!in_array($response->getStatusCode(), [200, 203, 300, 301, 302, 404, 410], true)) {
            return false;
        }

        //Check http headers
        $cache = static::parseCacheControl($response->getHeaderLine('Cache-Control'));<commit_msg>fixed cache validation<commit_after><?php
namespace Psr7Middlewares\Utils;

use RuntimeException;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;

/**
 * Utilities used by router middlewares
 */
trait CacheTrait
{
    /**
     * Check whether the response can be cached or not
     *
     * @param ServerRequestInterface $request
     * @param ResponseInterface      $response
     *
     * @return boolean
     */
    protected static function isCacheable(ServerRequestInterface $request, ResponseInterface $response)
    {
        if ($request->getMethod() !== 'GET') {
            return false;
        }

        if ($response->getStatusCode() !== 200) {
            return false;
        }

        //Check http headers
        $cache = static::parseCacheControl($response->getHeaderLine('Cache-Control'));
{'fraction_non_alphanumeric': 0.10945273631840796, 'fraction_numerical': 0.014372581536760642, 'mean_word_length': 2.9262472885032538, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '1845154', 'n_tokens_mistral': 506, 'n_tokens_neox': 482, 'n_words': 122}