<commit_before><?php
class Vps_Model_ProxyCache extends Vps_Model_Proxy
{
    protected $_cacheSettings;
    protected $_cacheData = array();
    private $_cache;
    protected $_rowClass = 'Vps_Model_ProxyCache_Row';
    protected $_rowsetClass = 'Vps_Model_ProxyCache_Rowset';

    public function __construct(array $config = array())
    {
        if (isset($config['cacheSettings'])) $this->_cacheSettings = $config['cacheSettings'];
        parent::__construct($config);
    }

    public function getRows($where=null, $order=null, $limit=null, $start=null)
    {

        if (!is_object($where)) {
            if (is_string($where)) $where = array($where);
            $select = $this->select($where, $order, $limit, $start);
        } else {
            $select = $where;
        }
        if ($select->getPart(Vps_Model_Select::WHERE_EQUALS) || $select->getPart(Vps_Model_Select::WHERE_NULL)) {
            $cacheSetting = $this->_getCacheSetting($select);
            if ($cacheSetting) {


                $cacheId = $this->_getCacheId($cacheSetting);

                if (!isset($this->_cacheData[$cacheId])) {
                    if (!$this->_cacheData[$cacheId] = $this->_getCache()->load($cacheId)) {
                        $this->_cacheData[$cacheId] = $this->_getCacheData($cacheSetting);
                        $this->_getCache()->save($this->_cacheData[$cacheId], $cacheId);
                    }
                }
                $whereEquals = $select->getPart(Vps_Model_Select::WHERE_EQUALS);
                $whereNull = $select->getPart(Vps_Model_Select::WHERE_NULL);
                $values = array();
                foreach ($cacheSetting['index'] as $value) {
                    if ($whereEquals) {
                        if (isset($whereEquals[$value])) $values[] = $this->_escapeSearchKeyElement($whereEquals[$value]);
                    }
                    if ($whereNull) {
                        foreach (array_values($whereNull) as $whereKey => $whereValue) {
                            if ($whereValue == $value)
                                $values[] = $this->_escapeSearchKeyElement(null);
                        }
                    }
                }
                $valuesbefore = $values;
                $v = implode($values, '_');

                if (isset($this->_cacheData[$cacheId][$v]))
                    $data = $this->_cacheData[$cacheId][$v];
                else {
                    $data = array();
                }



                return new $this->_rowsetClass(array(
                    'model' => $this,
                    'rowClass' => $this->_rowClass,
                    'cacheData' => $data
                ));
            }
        }
        return parent::getRows($where, $order, $limit, $start);
    }

    private function _getCacheSetting ($where)
    {
        $necessary = array();
        $whereEquals = $where->getPart(Vps_Model_Select::WHERE_EQUALS);
        $whereNull = $where->getPart(Vps_Model_Select::WHERE_NULL);

        foreach ($this->_cacheSettings as $cacheSetting) {
            $check = true;
            foreach ($cacheSetting['index'] as $value) {
                $cacheSettingCheck = false;
                if ($whereEquals) {
                    if (isset($whereEquals[$value])) {
                        $values[] = $this->_escapeSearchKeyElement($whereEquals[$value]);
                        $cacheSettingCheck = true;
                    }
                }
                if ($whereNull) {
                    foreach (array_values($whereNull) as $whereKey => $whereValue) {
                        if ($whereValue == $value) {
                            $values[] = $this->_escapeSearchKeyElement(null);
                                $cacheSettingCheck = true;
                        }
                    }
                }
                if ($cacheSettingCheck == false) {
                    $check = false;
                }
            }
            if ($check) {
                return $cacheSetting;
            }
        }
        return null;
    }

    private function _getCacheId ($cacheSetting)
    {
        $parts = array();
        $parts[] = $this->getUniqueIdentifier();
        $parts[] = implode ($cacheSetting['index'], '_');
        $parts[] = implode ($cacheSetting['columns'], '_');
        return implode ($parts, '_');
    }

    private function _getCache()
    {
        if (!$this->_cache) {
            $frontendOptions = array('lifetime' => 3600, 'automatic_serialization' => true);
            $backendOptions = array('cache_dir' => 'application/cache/model');
            $this->_cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
        }

        return $this->_cache;<commit_msg>Vps_Cache verwenden um default backend options zu haben<commit_after><?php
class Vps_Model_ProxyCache extends Vps_Model_Proxy
{
    protected $_cacheSettings;
    protected $_cacheData = array();
    private $_cache;
    protected $_rowClass = 'Vps_Model_ProxyCache_Row';
    protected $_rowsetClass = 'Vps_Model_ProxyCache_Rowset';

    public function __construct(array $config = array())
    {
        if (isset($config['cacheSettings'])) $this->_cacheSettings = $config['cacheSettings'];
        parent::__construct($config);
    }

    public function getRows($where=null, $order=null, $limit=null, $start=null)
    {

        if (!is_object($where)) {
            if (is_string($where)) $where = array($where);
            $select = $this->select($where, $order, $limit, $start);
        } else {
            $select = $where;
        }
        if ($select->getPart(Vps_Model_Select::WHERE_EQUALS) || $select->getPart(Vps_Model_Select::WHERE_NULL)) {
            $cacheSetting = $this->_getCacheSetting($select);
            if ($cacheSetting) {


                $cacheId = $this->_getCacheId($cacheSetting);

                if (!isset($this->_cacheData[$cacheId])) {
                    if (!$this->_cacheData[$cacheId] = $this->_getCache()->load($cacheId)) {
                        $this->_cacheData[$cacheId] = $this->_getCacheData($cacheSetting);
                        $this->_getCache()->save($this->_cacheData[$cacheId], $cacheId);
                    }
                }
                $whereEquals = $select->getPart(Vps_Model_Select::WHERE_EQUALS);
                $whereNull = $select->getPart(Vps_Model_Select::WHERE_NULL);
                $values = array();
                foreach ($cacheSetting['index'] as $value) {
                    if ($whereEquals) {
                        if (isset($whereEquals[$value])) $values[] = $this->_escapeSearchKeyElement($whereEquals[$value]);
                    }
                    if ($whereNull) {
                        foreach (array_values($whereNull) as $whereKey => $whereValue) {
                            if ($whereValue == $value)
                                $values[] = $this->_escapeSearchKeyElement(null);
                        }
                    }
                }
                $valuesbefore = $values;
                $v = implode($values, '_');

                if (isset($this->_cacheData[$cacheId][$v]))
                    $data = $this->_cacheData[$cacheId][$v];
                else {
                    $data = array();
                }



                return new $this->_rowsetClass(array(
                    'model' => $this,
                    'rowClass' => $this->_rowClass,
                    'cacheData' => $data
                ));
            }
        }
        return parent::getRows($where, $order, $limit, $start);
    }

    private function _getCacheSetting ($where)
    {
        $necessary = array();
        $whereEquals = $where->getPart(Vps_Model_Select::WHERE_EQUALS);
        $whereNull = $where->getPart(Vps_Model_Select::WHERE_NULL);

        foreach ($this->_cacheSettings as $cacheSetting) {
            $check = true;
            foreach ($cacheSetting['index'] as $value) {
                $cacheSettingCheck = false;
                if ($whereEquals) {
                    if (isset($whereEquals[$value])) {
                        $values[] = $this->_escapeSearchKeyElement($whereEquals[$value]);
                        $cacheSettingCheck = true;
                    }
                }
                if ($whereNull) {
                    foreach (array_values($whereNull) as $whereKey => $whereValue) {
                        if ($whereValue == $value) {
                            $values[] = $this->_escapeSearchKeyElement(null);
                                $cacheSettingCheck = true;
                        }
                    }
                }
                if ($cacheSettingCheck == false) {
                    $check = false;
                }
            }
            if ($check) {
                return $cacheSetting;
            }
        }
        return null;
    }

    private function _getCacheId ($cacheSetting)
    {
        $parts = array();
        $parts[] = $this->getUniqueIdentifier();
        $parts[] = implode ($cacheSetting['index'], '_');
        $parts[] = implode ($cacheSetting['columns'], '_');
        return implode ($parts, '_');
    }

    private function _getCache()
    {
        if (!$this->_cache) {
            $frontendOptions = array('lifetime' => 3600, 'automatic_serialization' => true);
            $backendOptions = array('cache_dir' => 'application/cache/model');
            $this->_cache = Vps_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
        }

        return $this->_cache;
{'fraction_non_alphanumeric': 0.1375352186162997, 'fraction_numerical': 0.0008348116456224564, 'mean_word_length': 1.64167585446527, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 83, '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': '6504892', 'n_tokens_mistral': 2552, 'n_tokens_neox': 2414, 'n_words': 428}