english/libraries/joomla/cache/cache.php
/**
	 * Set lock flag on cached item
	 *
	 * @param   string   $id       The cache data id
	 * @param   string   $group    The cache data group
	 * @param            $locktime
	 *
	 * @return  boolean  True on success, false otherwise.
	 * @since   11.1
	 */
Set lock flag on cached item
@param   string   $id       The cache data id
@param   string   $group    The cache data group
@param            $locktime

@return  boolean  True on success, false otherwise.
Set lock flag on cached item @param string $id The cache data id @param string $group The cache data group @param $locktime @return boolean True on success false otherwise .
public function lock($id,$group=null,$locktime=null)
	{
		$returning = new stdClass;
		$returning->locklooped = false;
		$group = ($group) ? $group : $this->_options['defaultgroup'];
		$locktime = ($locktime) ? $locktime : $this->_options['locktime'];
		$handler = $this->_getStorage();
		if (!JError::isError($handler) && $this->_options['locking'] == true && $this->_options['caching'] == true) {
			$locked = $handler->lock($id, $group, $locktime);
			if ($locked !== false) {
				return $locked;
			}
		}
		$curentlifetime = $this->_options['lifetime'];
		$this->_options['lifetime'] = $locktime;
		$looptime 	= $locktime * 10;
		$id2 		= $id.'_lock';
		if ($this->_options['locking'] == true && $this->_options['caching'] == true ) {
			$data_lock = $this->get($id2, $group);
		} else {
			$data_lock = false;
			$returning->locked = false;
		}
		if ( $data_lock !== false ) {
			$lock_counter = 0;
			while ( $data_lock !== false ) {
				if ( $lock_counter > $looptime) {
					$returning->locked 		= false;
					$returning->locklooped 	= true;
					break;
				}
				usleep(100);
				$data_lock = $this->get($id2, $group);
				$lock_counter++;
			}
		}
		if ($this->_options['locking'] == true && $this->_options['caching'] == true ) {
			$returning->locked = $this->store(1, $id2, $group);
		}
		$this->_options['lifetime'] = $curentlifetime;
		return $returning;
	}
public function lock ( $ id , $ group = null , $ locktime = null ) { $ returning = new stdClass ; $ returning -> locklooped = false ; $ group = ( $ group ) ? $ group : $ this -> _options [ 'defaultgroup' ] ; $ locktime = ( $ locktime ) ? $ locktime : $ this -> _options [ 'locktime' ] ; $ handler = $ this -> _getStorage ( ) ; if ( ! JError :: isError ( $ handler ) && $ this -> _options [ 'locking' ] == true && $ this -> _options [ 'caching' ] == true ) { $ locked = $ handler -> lock ( $ id , $ group , $ locktime ) ; if ( $ locked !== false ) { return $ locked ; } } $ curentlifetime = $ this -> _options [ 'lifetime' ] ; $ this -> _options [ 'lifetime' ] = $ locktime ; $ looptime = $ locktime * 10 ; $ id2 = $ id . '_lock' ; if ( $ this -> _options [ 'locking' ] == true && $ this -> _options [ 'caching' ] == true ) { $ data_lock = $ this -> get ( $ id2 , $ group ) ; } else { $ data_lock = false ; $ returning -> locked = false ; } if ( $ data_lock !== false ) { $ lock_counter = 0 ; while ( $ data_lock !== false ) { if ( $ lock_counter > $ looptime ) { $ returning -> locked = false ; $ returning -> locklooped = true ; break ; } usleep ( 100 ) ; $ data_lock = $ this -> get ( $ id2 , $ group ) ; $ lock_counter ++ ; } } if ( $ this -> _options [ 'locking' ] == true && $ this -> _options [ 'caching' ] == true ) { $ returning -> locked = $ this -> store ( 1 , $ id2 , $ group ) ; } $ this -> _options [ 'lifetime' ] = $ curentlifetime ; return $ returning ; }
Set lock flag on cached item
 @param   string   $id       The cache data id
 @param   string   $group    The cache data group
 @param            $locktime
Set lock flag on cached item @param string $id The cache data id @param string $group The cache data group @param $locktime
// Get the default group // Get the default locktime // Allow storage handlers to perform locking on their own // NOTE drivers with lock need also unlock or unlocking will fail because of false $id // fallback // set lifetime to locktime for storing in children // loop until you find that the lock has been released.  that implies that data get from other thread has finished // revert lifetime to previous one