<commit_before><?php
/**
 * Created by PhpStorm.
 * User: joseph
 * Date: 5/27/16
 * Time: 9:16 AM
 */

namespace Poznet\ConfigBundle\Service;


use Doctrine\Common\Cache\CacheProvider;
use Poznet\ConfigBundle\Entity\Config;
use Doctrine\ORM\EntityManager;

/**
 * Klasa  zarządzająca konfiguracją
 * Class ConfigService
 * @package ConfigBundle\Service
 */
class ConfigService
{

    private $em;
    private $cache;

    public function __construct(EntityManager $em, CacheProvider $cache)
    {
        $this->em=$em;
        $this->cache=$cache;
    }


    /**
     * Gets  config  value
     * @param $name
     * @return null
     */
    public function get($name){
        if($this->cache->contains($name))
            return $this->cache->fetch($name);

        $config=$this->em->getRepository("ConfigBundle:Config")->findOneByName($name);
        if(!$config)
            return null;
        $this->cache->save($name,$config->getValue());
        return $config->getValue();
    }

    /**
     * Sets config value
     * @param $name
     * @param $value
     * @return bool
     */
    public function set($name,$value){
        $config=$this->em->getRepository("ConfigBundle:Config")->findOneByName($name);
        if(!$config) {
            $config = new Config();<commit_msg>add doctrine query cache<commit_after><?php
/**
 * Created by PhpStorm.
 * User: joseph
 * Date: 5/27/16
 * Time: 9:16 AM
 */

namespace Poznet\ConfigBundle\Service;


use Doctrine\Common\Cache\CacheProvider;
use Poznet\ConfigBundle\Entity\Config;
use Doctrine\ORM\EntityManager;

/**
 * Klasa  zarządzająca konfiguracją
 * Class ConfigService
 * @package ConfigBundle\Service
 */
class ConfigService
{

    private $em;
    private $cache;

    public function __construct(EntityManager $em, CacheProvider $cache)
    {
        $this->em=$em;
        $this->cache=$cache;
    }


    /**
     * Gets  config  value
     * @param $name
     * @return null
     */
    public function get($name){
        if($this->cache->contains($name))
            return $this->cache->fetch($name);

        $config=$this->em->getRepository("ConfigBundle:Config")->findOneByName($name);
        if(!$config)
            return null;
        $this->cache->save($name,$config->getValue(),3600);
        return $config->getValue();
    }

    /**
     * Sets config value
     * @param $name
     * @param $value
     * @return bool
     */
    public function set($name,$value){
        $config=$this->em->getRepository("ConfigBundle:Config")->findOneByName($name);
        if(!$config) {
            $config = new Config();
{'fraction_non_alphanumeric': 0.15115384615384617, 'fraction_numerical': 0.007692307692307693, 'mean_word_length': 2.6225626740947074, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '6809341', 'n_tokens_mistral': 809, 'n_tokens_neox': 794, 'n_words': 156}