/**
  * test that fields() method cache detects schema name changes
  *
  * @return void
  */
 public function testFieldsCacheKeyWithSchemanameChange()
 {
     if ($this->db instanceof Postgres || $this->db instanceof Sqlserver) {
         $this->markTestSkipped('Cannot run this test with SqlServer or Postgres');
     }
     Cache::delete('method_cache', '_cake_core_');
     DboSource::$methodCache = array();
     $Article = ClassRegistry::init('Article');
     $ds = $Article->getDataSource();
     $ds->cacheMethods = true;
     $first = $ds->fields($Article);
     $Article->schemaName = 'secondSchema';
     $ds = $Article->getDataSource();
     $ds->cacheMethods = true;
     $second = $ds->fields($Article);
     $this->assertEquals(2, count(DboSource::$methodCache['fields']));
 }
Example #2
0
/**
 * Cache a value into the methodCaches.  Will respect the value of DboSource::$cacheMethods.
 * Will retrieve a value from the cache if $value is null.
 *
 * If caching is disabled and a write is attempted, the $value will be returned.
 * A read will either return the value or null.
 *
 * @param string $method Name of the method being cached.
 * @param string $key The keyname for the cache operation.
 * @param mixed $value The value to cache into memory.
 * @return mixed Either null on failure, or the value if its set.
 */
	public function cacheMethod($method, $key, $value = null) {
		if ($this->cacheMethods === false) {
			return $value;
		}
		if (empty(self::$methodCache)) {
			self::$methodCache = Cache::read('method_cache', '_cake_core_');
		}
		if ($value === null) {
			return (isset(self::$methodCache[$method][$key])) ? self::$methodCache[$method][$key] : null;
		}
		$this->_methodCacheChange = true;
		return self::$methodCache[$method][$key] = $value;
	}
Example #3
0
 protected function _clearCache()
 {
     DboSource::$methodCache = array();
     $keys = Cache::configured();
     foreach ($keys as $key) {
         Cache::clear(false, $key);
     }
     ClassRegistry::flush();
 }
 /**
  * Clear all caches present related to models
  *
  * Before the 'after' callback method be called is needed to clear all caches.
  * Without it any model operations will use cached data instead of real/modified
  * data.
  *
  * @return void
  */
 protected function _clearCache()
 {
     // Clear the cache
     DboSource::$methodCache = array();
     $keys = Cache::configured();
     foreach ($keys as $key) {
         Cache::clear(false, $key);
     }
     ClassRegistry::flush();
     // Refresh the model, in case something changed
     if ($this->Version instanceof MigrationVersion) {
         $this->Version->initVersion();
     }
 }
Example #5
0
 /**
  * Clear all caches present related to models
  *
  * Before the 'after' callback method be called is needed to clear all caches.
  * Without it any model operations will use cached data instead of real/modified
  * data.
  *
  * @return void
  */
 protected function _clearCache()
 {
     // Clear the cache
     DboSource::$methodCache = array();
     $keys = Cache::configured();
     foreach ($keys as $key) {
         Cache::clear(false, $key);
     }
     ClassRegistry::flush();
     // Refresh the model, in case something changed
     $options = array('class' => 'Migrations.SchemaMigration', 'ds' => $this->connection);
     $this->Version->Version =& ClassRegistry::init($options);
     $this->Version->Version->setDataSource($this->connection);
 }