<commit_before><?php namespace Anomaly\PostsModule\Post;

use Anomaly\PostsModule\Post\Contract\PostInterface;
use Anomaly\SettingsModule\Setting\Contract\SettingRepositoryInterface;
use Illuminate\Contracts\Support\Arrayable;

/**
 * Class PostHttp
 *
 * @link          http://anomaly.is/streams-platform
 * @author        AnomalyLabs, Inc. <<EMAIL>>
 * @author        <NAME> <<EMAIL>>
 * @package       Anomaly\PostsModule\Post
 */
class PostHttp
{

    /**
     * The setting repository.
     *
     * @var SettingRepositoryInterface
     */
    protected $settings;

    /**
     * Create a new PostHttp instance.
     *
     * @param SettingRepositoryInterface $settings
     */
    public function __construct(SettingRepositoryInterface $settings)
    {
        $this->settings = $settings;
    }

    /**
     * Cache the post's HTTP response.
     *
     * @param PostInterface|Arrayable $post
     */
    public function cache(PostInterface $post)
    {
        if (!$post->isLive()) {
            return;
        }

        $ttl      = $post->getTtl();
        $response = $post->getResponse();

        // if no post TTL use the post type TTL.
        if ($ttl === null && $type = $post->getType()) {
            $ttl = $type->getTtl();
        }

        // Default to settings.
        if ($ttl === null) {
            $ttl = $this->settings->get('anomaly.module.posts::ttl');
        }

        if ($ttl && $seconds = $ttl * 60) {

            $response->headers->set('Pragma', 'public');
            $response->headers->set('Content-Type', 'text/html');
            $response->headers->set('Etag', md5(json_encode($post->toArray())));
            $response->headers->set('Cache-Control', 'public,max-age=' . $seconds . ',s-maxage=' . $seconds);
            $response->headers->set(
                'Last-Modified',
                $post->lastModified()->setTimezone('GMT')->format('D, d M Y H:i:s')
            );

            $response->setTtl($seconds);
        }
    }
}<commit_msg>Better cache<commit_after><?php namespace Anomaly\PostsModule\Post;

use Anomaly\PostsModule\Post\Contract\PostInterface;
use Anomaly\SettingsModule\Setting\Contract\SettingRepositoryInterface;
use Illuminate\Contracts\Support\Arrayable;

/**
 * Class PostHttp
 *
 * @link          http://anomaly.is/streams-platform
 * @author        AnomalyLabs, Inc. <<EMAIL>>
 * @author        <NAME> <<EMAIL>>
 * @package       Anomaly\PostsModule\Post
 */
class PostHttp
{

    /**
     * The setting repository.
     *
     * @var SettingRepositoryInterface
     */
    protected $settings;

    /**
     * Create a new PostHttp instance.
     *
     * @param SettingRepositoryInterface $settings
     */
    public function __construct(SettingRepositoryInterface $settings)
    {
        $this->settings = $settings;
    }

    /**
     * Cache the post's HTTP response.
     *
     * @param PostInterface|Arrayable $post
     */
    public function cache(PostInterface $post)
    {
        if (!$post->isLive()) {
            return;
        }

        $ttl      = $post->getTtl();
        $response = $post->getResponse();

        // if no post TTL use the post type TTL.
        if ($ttl === null && $type = $post->getType()) {
            $ttl = $type->getTtl();
        }

        // Default to settings.
        if ($ttl === null) {
            $ttl = $this->settings->get('anomaly.module.posts::ttl');
        }

        if ($ttl && $seconds = $ttl * 60) {

            $response->headers->set('Content-Type', 'text/html');
            $response->headers->set('Cache-Controle', 'must-revalidate');
            $response->headers->set('Etag', md5(json_encode($post->toArray())));
            $response->headers->set(
                'Last-Modified',
                $post->lastModified()->setTimezone('GMT')->format('D, d M Y H:i:s T')
            );

            $response->setTtl($seconds);
        }
    }
}
{'fraction_non_alphanumeric': 0.15634595701125895, 'fraction_numerical': 0.0015353121801432957, 'mean_word_length': 2.0803782505910164, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 57, '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': '1165222', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1138, 'n_words': 221}