src/FileCache.php
public function set($name, $value, $ttl = 0){

		if($ttl <= 0) $ttl = self::TTL_FUTURE;

		if(is_resource($value)){

			throw new CacheException('Cannot cache values of type "resource"');
		}

		if(!$this->validateValueSize($value)){

			ExceptionHandler::notice("Value in $name is too big to be stored in file cache.");
		}

		$file = $this->_getFileName($name);

		$fp = @fopen($this->_cache_path . $file, 'wb');

		if(is_resource($fp)){

			$result = @fwrite($fp, serialize($value));
			$result = ($result && @fclose($fp));
			$result =
				($result && @touch($this->_cache_path . $file, time() + $ttl));

			// Clear expired cache-files every once-in-a-while

			if($result && rand(1, self::CLEAR_INTERVAL) == self::CLEAR_INTERVAL){

				$this->_clearExpired();


			}

			return $result;
		}
		else{

			return false;
		}
	}
public function set($name, $value, $ttl = 0){

		if($ttl <= 0) $ttl = self::TTL_FUTURE;

		if(is_resource($value)){

			throw new CacheException('Cannot cache values of type "resource"');
		}

		if(!$this->validateValueSize($value)){

			ExceptionHandler::notice("Value in $name is too big to be stored in file cache.");
		}

		$file = $this->_getFileName($name);

		$fp = @fopen($this->_cache_path . $file, 'wb');

		if(is_resource($fp)){

			$result = @fwrite($fp, serialize($value));
			$result = ($result && @fclose($fp));
			$result =
				($result && @touch($this->_cache_path . $file, time() + $ttl));

			// Clear expired cache-files every once-in-a-while

			if($result && rand(1, self::CLEAR_INTERVAL) == self::CLEAR_INTERVAL){

				$this->_clearExpired();


			}

			return $result;
		}
		else{

			return false;
		}
	}
public function set ( $ name , $ value , $ ttl = 0 ) { if ( $ ttl <= 0 ) $ ttl = self :: TTL_FUTURE ; if ( is_resource ( $ value ) ) { throw new CacheException ( 'Cannot cache values of type "resource"' ) ; } if ( ! $ this -> validateValueSize ( $ value ) ) { ExceptionHandler :: notice ( "Value in $name is too big to be stored in file cache." ) ; } $ file = $ this -> _getFileName ( $ name ) ; $ fp = @ fopen ( $ this -> _cache_path . $ file , 'wb' ) ; if ( is_resource ( $ fp ) ) { $ result = @ fwrite ( $ fp , serialize ( $ value ) ) ; $ result = ( $ result && @ fclose ( $ fp ) ) ; $ result = ( $ result && @ touch ( $ this -> _cache_path . $ file , time ( ) + $ ttl ) ) ; // Clear expired cache-files every once-in-a-while if ( $ result && rand ( 1 , self :: CLEAR_INTERVAL ) == self :: CLEAR_INTERVAL ) { $ this -> _clearExpired ( ) ; } return $ result ; } else { return false ; } }
Add an entry to the FileCache.

<p>Due to the way FileCache keeps track of expiry dates, setting {@link
$ttl} to zero will set the expiry time to FileCache::TTL_FUTURE which by
default is set to 365 days in the future.</p>

<p>Every successful "set" has a chance of triggering {@link
FileCache::_clearExpired()} which clears expired entries from the
cache-path. The chance of trigging this method is controlled through the
{@link FileCache::CLEAR_INTERVAL} constant. By default it will be
triggered once every 50 sets.</p>

@param string $name
@param mixed $value
@param integer $ttl
@return boolean
@throws CacheException
@see Cache::set()
@see FileCache::_clearExpired()
Add an entry to the FileCache .