<commit_before><?php

/*
 * This file is part of twig-cache-extension.
 *
 * (c) Alexander <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Brother\CommonBundle\Twig\CacheExtension\CacheStrategy;

use Brother\CommonBundle\Twig\CacheExtension\CacheProviderInterface;
use Brother\CommonBundle\Twig\CacheExtension\CacheStrategyInterface;
use Brother\CommonBundle\AppDebug;

/**
 * Strategy for caching with a pre-defined lifetime.
 *
 * The value passed to the strategy is the lifetime of the cache block in
 * seconds.
 *
 * @author Alexander <<EMAIL>>
 */
class LifetimeCacheStrategy implements CacheStrategyInterface
{
    const PREFIX='v13_';
    private $cache;

    /**
     * @param CacheProviderInterface $cache
     */
    public function __construct(CacheProviderInterface $cache)
    {
        $this->cache = $cache;
    }

    /**
     * {@inheritDoc}
     */
    public function fetchBlock($key)
    {
        return $this->cache->fetch($key['key']);
    }

    /**
     * {@inheritDoc}
     */
    public function generateKey($annotation, $value)
    {
        if (is_array($value)) {
            $lifetime = $value['lifetime'];
            $key = self::PREFIX . $annotation . '_' . $value['key'];
        } else {
            if (! is_numeric($value)) {
                //todo: specialized exception
                throw new \RuntimeException('Value is not a valid lifetime.');
            }
            $lifetime = $value;
            $key = self::PREFIX . $annotation;
        }

        return array(
            'lifetime' => $lifetime,
            'key' => '__LCS__' . $key,
        );
    }

    /**
     * {@inheritDoc}
     */
    public function saveBlock($key, $block)
    {
        return $this->cache->save($key['key'], $block, $key['lifetime']);
    }
}
<commit_msg>Check news<commit_after><?php

/*
 * This file is part of twig-cache-extension.
 *
 * (c) Alexander <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Brother\CommonBundle\Twig\CacheExtension\CacheStrategy;

use Brother\CommonBundle\Twig\CacheExtension\CacheProviderInterface;
use Brother\CommonBundle\Twig\CacheExtension\CacheStrategyInterface;
use Brother\CommonBundle\AppDebug;

/**
 * Strategy for caching with a pre-defined lifetime.
 *
 * The value passed to the strategy is the lifetime of the cache block in
 * seconds.
 *
 * @author Alexander <<EMAIL>>
 */
class LifetimeCacheStrategy implements CacheStrategyInterface
{
    const PREFIX='v14_';
    private $cache;

    /**
     * @param CacheProviderInterface $cache
     */
    public function __construct(CacheProviderInterface $cache)
    {
        $this->cache = $cache;
    }

    /**
     * {@inheritDoc}
     */
    public function fetchBlock($key)
    {
        return $this->cache->fetch($key['key']);
    }

    /**
     * {@inheritDoc}
     */
    public function generateKey($annotation, $value)
    {
        if (is_array($value)) {
            $lifetime = $value['lifetime'];
            $key = self::PREFIX . $annotation . '_' . $value['key'];
        } else {
            if (! is_numeric($value)) {
                //todo: specialized exception
                throw new \RuntimeException('Value is not a valid lifetime.');
            }
            $lifetime = $value;
            $key = self::PREFIX . $annotation;
        }

        return array(
            'lifetime' => $lifetime,
            'key' => '__LCS__' . $key,
        );
    }

    /**
     * {@inheritDoc}
     */
    public function saveBlock($key, $block)
    {
        return $this->cache->save($key['key'], $block, $key['lifetime']);
    }
}

{'fraction_non_alphanumeric': 0.1318217769575534, 'fraction_numerical': 0.0010545742156604272, 'mean_word_length': 2.345679012345679, 'pattern_counts': {'":': 0, '<': 13, '<?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': '675556', 'n_tokens_mistral': 1078, 'n_tokens_neox': 1057, 'n_words': 267}