Changeset 6363
- Timestamp:
- 12/07/07 15:52:16 (7 months ago)
- Files:
-
- trunk/lib/cache/sfAPCCache.class.php (modified) (1 diff)
- trunk/lib/cache/sfCache.class.php (modified) (6 diffs)
- trunk/lib/cache/sfEAcceleratorCache.class.php (modified) (1 diff)
- trunk/lib/cache/sfFileCache.class.php (modified) (7 diffs)
- trunk/lib/cache/sfMemcacheCache.class.php (modified) (6 diffs)
- trunk/lib/cache/sfSQLiteCache.class.php (modified) (3 diffs)
- trunk/lib/cache/sfXCacheCache.class.php (modified) (1 diff)
- trunk/test/unit/cache/sfCacheDriverTests.class.php (modified) (3 diffs)
- trunk/test/unit/cache/sfCacheTest.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/cache/sfAPCCache.class.php
r6362 r6363 24 24 * Initializes this sfCache instance. 25 25 * 26 * Available parameters:26 * Available options: 27 27 * 28 * * see sfCache for default parameters available for all drivers28 * * see sfCache for options available for all drivers 29 29 * 30 30 * @see sfCache 31 31 */ 32 public function initialize($ parameters = array())32 public function initialize($options = array()) 33 33 { 34 parent::initialize($ parameters);34 parent::initialize($options); 35 35 36 36 if (!function_exists('apc_store') || !ini_get('apc.enabled')) trunk/lib/cache/sfCache.class.php
r5016 r6363 24 24 25 25 protected 26 $ parameterHolder = null;26 $options = array(); 27 27 28 28 /** … … 31 31 * @see initialize() 32 32 */ 33 public function __construct($ parameters = array())34 { 35 $this->initialize($ parameters);33 public function __construct($options = array()) 34 { 35 $this->initialize($options); 36 36 } 37 37 … … 39 39 * Initializes this sfCache instance. 40 40 * 41 * @param array An a ssociative array of initialization parameters.42 * 43 * Available parameters:41 * @param array An array of options. 42 * 43 * Available options: 44 44 * 45 45 * * automaticCleaningFactor (optional): The automatic cleaning process destroy too old (for the given life time) (default value: 1000) … … 51 51 * * lifetime (optional): The default life time (default value: 86400) 52 52 * 53 * @return bool true, if initialization completes successfully, otherwise false.54 *55 53 * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfCache instance. 56 54 */ 57 public function initialize($parameters = array()) 58 { 59 $this->parameterHolder = new sfParameterHolder(); 60 $this->parameterHolder->add($parameters); 61 62 if (!$this->hasParameter('automaticCleaningFactor')) 63 { 64 $this->setParameter('automaticCleaningFactor', 1000); 65 } 66 67 if (!$this->hasParameter('lifetime')) 68 { 69 $this->setParameter('lifetime', 86400); 70 } 55 public function initialize($options = array()) 56 { 57 $this->options = array_merge(array('automaticCleaningFactor' => 1000, 'lifetime' => 86400), $options); 71 58 } 72 59 … … 177 164 public function getLifetime($lifetime) 178 165 { 179 return is_null($lifetime) ? $this->get Parameter('lifetime') : $lifetime;166 return is_null($lifetime) ? $this->getOption('lifetime') : $lifetime; 180 167 } 181 168 … … 191 178 192 179 /** 193 * Retrieves the parameters for the current request. 194 * 195 * @return sfParameterHolder The parameter holder 196 */ 197 public function getParameterHolder() 198 { 199 return $this->parameterHolder; 200 } 201 202 public function getParameter($name, $default = null) 203 { 204 return $this->parameterHolder->get($name, $default); 205 } 206 207 public function hasParameter($name) 208 { 209 return $this->parameterHolder->has($name); 210 } 211 212 public function setParameter($name, $value) 213 { 214 return $this->parameterHolder->set($name, $value); 180 * Gets an option value. 181 * 182 * @param string The option name 183 * 184 * @return mixed The option value 185 */ 186 public function getOption($name, $default = null) 187 { 188 return isset($this->options[$name]) ? $this->options[$name] : $default; 189 } 190 191 /** 192 * Sets an option value. 193 * 194 * @param string The option name 195 * @param mixed The option value 196 */ 197 public function setOption($name, $value) 198 { 199 return $this->options[$name] = $value; 215 200 } 216 201 trunk/lib/cache/sfEAcceleratorCache.class.php
r6362 r6363 24 24 * Initializes this sfCache instance. 25 25 * 26 * Available parameters:26 * Available options: 27 27 * 28 * * see sfCache for default parameters available for all drivers28 * * see sfCache for options available for all drivers 29 29 * 30 30 * @see sfCache 31 31 */ 32 public function initialize($ parameters = array())32 public function initialize($options = array()) 33 33 { 34 parent::initialize($ parameters);34 parent::initialize($options); 35 35 36 36 if (!function_exists('eaccelerator_put') || !ini_get('eaccelerator.enable')) trunk/lib/cache/sfFileCache.class.php
r5309 r6363 28 28 * Initializes this sfCache instance. 29 29 * 30 * Available parameters:30 * Available options: 31 31 * 32 32 * * cacheDir: The directory where to put cache files 33 33 * 34 * * see sfCache for default parameters available for all drivers 35 * 36 * @param array An associative array of initialization parameters. 37 * 38 * @return bool true, if initialization completes successfully, otherwise false. 39 * 40 * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfCache. 34 * * see sfCache for options available for all drivers 35 * 36 * @see sfCache 41 37 */ 42 public function initialize($ parameters = array())43 { 44 parent::initialize($ parameters);45 46 if (!$this->get Parameter('cacheDir'))47 { 48 throw new sfInitializationException('You must pass a "cacheDir" parameterto initialize a sfFileCache object.');49 } 50 51 $this->setCacheDir($this->get Parameter('cacheDir'));38 public function initialize($options = array()) 39 { 40 parent::initialize($options); 41 42 if (!$this->getOption('cacheDir')) 43 { 44 throw new sfInitializationException('You must pass a "cacheDir" option to initialize a sfFileCache object.'); 45 } 46 47 $this->setCacheDir($this->getOption('cacheDir')); 52 48 } 53 49 … … 78 74 public function set($key, $data, $lifetime = null) 79 75 { 80 if ($this->get Parameter('automaticCleaningFactor') > 0 && rand(1, $this->getParameter('automaticCleaningFactor')) == 1)76 if ($this->getOption('automaticCleaningFactor') > 0 && rand(1, $this->getOption('automaticCleaningFactor')) == 1) 81 77 { 82 78 $this->clean(sfCache::OLD); … … 105 101 $regexp = self::patternToRegexp($pattern); 106 102 $paths = array(); 107 foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->get Parameter('cacheDir'))) as $path)103 foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->getOption('cacheDir'))) as $path) 108 104 { 109 if (preg_match($regexp, str_replace($this->get Parameter('cacheDir').DIRECTORY_SEPARATOR, '', $path)))105 if (preg_match($regexp, str_replace($this->getOption('cacheDir').DIRECTORY_SEPARATOR, '', $path))) 110 106 { 111 107 $paths[] = $path; … … 115 111 else 116 112 { 117 $paths = glob($this->get Parameter('cacheDir').DIRECTORY_SEPARATOR.str_replace(sfCache::SEPARATOR, DIRECTORY_SEPARATOR, $pattern).self::EXTENSION);113 $paths = glob($this->getOption('cacheDir').DIRECTORY_SEPARATOR.str_replace(sfCache::SEPARATOR, DIRECTORY_SEPARATOR, $pattern).self::EXTENSION); 118 114 } 119 115 … … 136 132 public function clean($mode = sfCache::ALL) 137 133 { 138 if (!is_dir($this->get Parameter('cacheDir')))134 if (!is_dir($this->getOption('cacheDir'))) 139 135 { 140 136 return true; … … 142 138 143 139 $result = true; 144 foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->get Parameter('cacheDir'))) as $file)140 foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->getOption('cacheDir'))) as $file) 145 141 { 146 142 if (sfCache::ALL == $mode || time() > $this->read($file, self::READ_TIMEOUT)) … … 194 190 protected function getFilePath($key) 195 191 { 196 return $this->get Parameter('cacheDir').DIRECTORY_SEPARATOR.str_replace(sfCache::SEPARATOR, DIRECTORY_SEPARATOR, $key).self::EXTENSION;192 return $this->getOption('cacheDir').DIRECTORY_SEPARATOR.str_replace(sfCache::SEPARATOR, DIRECTORY_SEPARATOR, $key).self::EXTENSION; 197 193 } 198 194 trunk/lib/cache/sfMemcacheCache.class.php
r6362 r6363 26 26 * Initializes this sfCache instance. 27 27 * 28 * Available parameters: 29 * 30 * Available parameters: 28 * Available options: 31 29 * 32 30 * * memcache: A memcache object (optional) … … 38 36 * * servers: An array of additional servers (keys: host, port, persistent) 39 37 * 40 * * see sfCache for default parameters available for all drivers41 * 42 * @see sfCache 43 */ 44 public function initialize($ parameters = array())45 { 46 parent::initialize($ parameters);38 * * see sfCache for options available for all drivers 39 * 40 * @see sfCache 41 */ 42 public function initialize($options = array()) 43 { 44 parent::initialize($options); 47 45 48 46 if (!class_exists('Memcache')) … … 53 51 $this->prefix = md5(sfConfig::get('sf_app_dir')).self::SEPARATOR; 54 52 55 if ($this->get Parameter('memcache'))56 { 57 $this->memcache = $this->get Parameter('memcache');53 if ($this->getOption('memcache')) 54 { 55 $this->memcache = $this->getOption('memcache'); 58 56 } 59 57 else 60 58 { 61 59 $this->memcache = new Memcache(); 62 $method = $this->get Parameter('persistent', true) ? 'pconnect' : 'connect';63 if (!$this->memcache->$method($this->get Parameter('host', 'localhost'), $this->getParameter('port', 11211), $this->getParameter('timeout', 1)))60 $method = $this->getOption('persistent', true) ? 'pconnect' : 'connect'; 61 if (!$this->memcache->$method($this->getOption('host', 'localhost'), $this->getOption('port', 11211), $this->getOption('timeout', 1))) 64 62 { 65 throw new sfInitializationException(sprintf('Unable to connect to the memcache server (%s:%s).', $this->get Parameter('host', 'localhost'), $this->getParameter('port', 11211)));63 throw new sfInitializationException(sprintf('Unable to connect to the memcache server (%s:%s).', $this->getOption('host', 'localhost'), $this->getOption('port', 11211))); 66 64 } 67 65 68 if ($this->get Parameter('servers'))66 if ($this->getOption('servers')) 69 67 { 70 foreach ($this->get Parameter('servers') as $server)68 foreach ($this->getOption('servers') as $server) 71 69 { 72 70 $port = isset($server['port']) ? $server['port'] : 11211; … … 111 109 public function set($key, $data, $lifetime = null) 112 110 { 113 $lifetime = is_null($lifetime) ? $this->get Parameter('lifetime') : $lifetime;111 $lifetime = is_null($lifetime) ? $this->getOption('lifetime') : $lifetime; 114 112 115 113 // save metadata … … 117 115 118 116 // save key for removePattern() 119 if ($this->get Parameter('storeCacheInfo', false))117 if ($this->getOption('storeCacheInfo', false)) 120 118 { 121 119 $this->setCacheInfo($key); … … 177 175 public function removePattern($pattern) 178 176 { 179 if (!$this->get Parameter('storeCacheInfo', false))180 { 181 throw new sfCacheException('To use the "removePattern" method, you must set the "storeCacheInfo" parameterto "true".');177 if (!$this->getOption('storeCacheInfo', false)) 178 { 179 throw new sfCacheException('To use the "removePattern" method, you must set the "storeCacheInfo" option to "true".'); 182 180 } 183 181 trunk/lib/cache/sfSQLiteCache.class.php
r4586 r6363 26 26 * Initializes this sfCache instance. 27 27 * 28 * Available parameters:28 * Available options: 29 29 * 30 30 * * database: File where to put the cache database (or :memory: to store cache in memory) 31 31 * 32 * * see sfCache for default parameters available for all drivers33 * 34 * @see sfCache 35 */ 36 public function initialize($ parameters = array())32 * * see sfCache for options available for all drivers 33 * 34 * @see sfCache 35 */ 36 public function initialize($options = array()) 37 37 { 38 38 if (!extension_loaded('sqlite')) … … 41 41 } 42 42 43 parent::initialize($ parameters);44 45 if (!$this->get Parameter('database'))46 { 47 throw new sfInitializationException('You must pass a "database" parameterto initialize a sfSQLiteCache object.');48 } 49 50 $this->setDatabase($this->get Parameter('database'));43 parent::initialize($options); 44 45 if (!$this->getOption('database')) 46 { 47 throw new sfInitializationException('You must pass a "database" option to initialize a sfSQLiteCache object.'); 48 } 49 50 $this->setDatabase($this->getOption('database')); 51 51 } 52 52 … … 82 82 public function set($key, $data, $lifetime = null) 83 83 { 84 if ($this->get Parameter('automaticCleaningFactor') > 0 && rand(1, $this->getParameter('automaticCleaningFactor')) == 1)84 if ($this->getOption('automaticCleaningFactor') > 0 && rand(1, $this->getOption('automaticCleaningFactor')) == 1) 85 85 { 86 86 $this->clean(sfCache::OLD); trunk/lib/cache/sfXCacheCache.class.php
r6362 r6363 24 24 * Initializes this sfCache instance. 25 25 * 26 * Available parameters:26 * Available options: 27 27 * 28 * * see sfCache for default parameters available for all drivers28 * * see sfCache for options available for all drivers 29 29 * 30 30 * @see sfCache 31 31 */ 32 public function initialize($ parameters = array())32 public function initialize($options = array()) 33 33 { 34 parent::initialize($ parameters);34 parent::initialize($options); 35 35 36 36 if (!function_exists('xcache_set')) trunk/test/unit/cache/sfCacheDriverTests.class.php
r4579 r6363 64 64 65 65 $cache->clean(); 66 $cache->set Parameter('automaticCleaningFactor', 1);66 $cache->setOption('automaticCleaningFactor', 1); 67 67 $cache->set('foo', $data); 68 68 $cache->set('foo', $data); 69 69 $cache->set('foo', $data); 70 $cache->set Parameter('automaticCleaningFactor', 1000);70 $cache->setOption('automaticCleaningFactor', 1000); 71 71 72 72 // ->remove() … … 128 128 foreach (array(86400, 10) as $lifetime) 129 129 { 130 $cache-> getParameterHolder()->set('lifetime', $lifetime);130 $cache->setOption('lifetime', $lifetime); 131 131 $cache->set('foo', 'bar'); 132 132 … … 152 152 foreach (array(86400, 10) as $lifetime) 153 153 { 154 $cache-> getParameterHolder()->set('lifetime', $lifetime);154 $cache->setOption('lifetime', $lifetime); 155 155 $cache->set('bar', 'foo'); 156 156 trunk/test/unit/cache/sfCacheTest.php
r4957 r6363 33 33 $cache = new myCache(); 34 34 $cache->initialize(array('foo' => 'bar')); 35 $t->is($cache->get ParameterHolder()->get('foo'), 'bar', '->initialize() takes an array of parameters as its first argument');35 $t->is($cache->getOption('foo'), 'bar', '->initialize() takes an array of options as its first argument');