CacheBehavior::setup PHP Method

setup() public method

### Config - config The name of an existing Cache configuration to use. Default is 'default' - clearOnSave Whether or not to delete the cache on saves - clearOnDelete Whether or not to delete the cache on deletes - auto Automatically cache or look for 'cache' in the find conditions where the key is true or a duration
See also: Cache::config()
public setup ( Model $Model, array $config = [] )
$Model Model The calling model
$config array Configuration settings
    public function setup(Model $Model, $config = array())
    {
        $_defaults = array('config' => 'default', 'clearOnDelete' => true, 'clearOnSave' => true, 'auto' => false, 'gzip' => false);
        $settings = array_merge($_defaults, $config);
        $Model->_useDbConfig = $Model->useDbConfig;
        $ds = ConnectionManager::getDataSource($Model->useDbConfig);
        if (!in_array('cacher', ConnectionManager::sourceList())) {
            $settings += array('original' => $Model->useDbConfig, 'datasource' => 'Cacher.CacheSource');
            $settings = array_merge($ds->config, $settings);
            ConnectionManager::create('cacher', $settings);
        } else {
            $ds = ConnectionManager::getDataSource('cacher');
            $ds->config = array_merge($ds->config, $settings);
        }
        if (!isset($this->settings[$Model->alias])) {
            $this->settings[$Model->alias] = $settings;
        }
        $this->settings[$Model->alias] = array_merge($this->settings[$Model->alias], $settings);
    }