public function getOrCreate($filename, array $conditions = array(), $function, $file = false, $actual = false)
    {
        if (!is_callable($function)) {
            throw new \InvalidArgumentException('The argument $function should be callable');
        }

        $cacheFile = $this->getCacheFile($filename, true, true);
        $data = null;

        if (!$this->check($filename, $conditions)) {
            if(file_exists($cacheFile)) {
                unlink($cacheFile);
            }

            $data = call_user_func($function, $cacheFile);

            // Test if the closure wrote the file or if it returned the data
            if (!file_exists($cacheFile)) {
                $this->set($filename, $data);
            } else {
                $data = file_get_contents($cacheFile);
            }
        }

        return $file ? $this->getCacheFile($filename, $actual) : file_get_contents($cacheFile);
    }
public function getOrCreate($filename, array $conditions = array(), $function, $file = false, $actual = false)
    {
        if (!is_callable($function)) {
            throw new \InvalidArgumentException('The argument $function should be callable');
        }

        $cacheFile = $this->getCacheFile($filename, true, true);
        $data = null;

        if (!$this->check($filename, $conditions)) {
            if(file_exists($cacheFile)) {
                unlink($cacheFile);
            }

            $data = call_user_func($function, $cacheFile);

            // Test if the closure wrote the file or if it returned the data
            if (!file_exists($cacheFile)) {
                $this->set($filename, $data);
            } else {
                $data = file_get_contents($cacheFile);
            }
        }

        return $file ? $this->getCacheFile($filename, $actual) : file_get_contents($cacheFile);
    }
public function getOrCreate ( $ filename , array $ conditions = array ( ) , $ function , $ file = false , $ actual = false ) { if ( ! is_callable ( $ function ) ) { throw new \ InvalidArgumentException ( 'The argument $function should be callable' ) ; } $ cacheFile = $ this -> getCacheFile ( $ filename , true , true ) ; $ data = null ; if ( ! $ this -> check ( $ filename , $ conditions ) ) { if ( file_exists ( $ cacheFile ) ) { unlink ( $ cacheFile ) ; } $ data = call_user_func ( $ function , $ cacheFile ) ; // Test if the closure wrote the file or if it returned the data if ( ! file_exists ( $ cacheFile ) ) { $ this -> set ( $ filename , $ data ) ; } else { $ data = file_get_contents ( $ cacheFile ) ; } } return $ file ? $ this -> getCacheFile ( $ filename , $ actual ) : file_get_contents ( $ cacheFile ) ; }
Get or create the cache entry

@param string $filename the cache file name
@param array $conditions an array of conditions about expiration
@param \Closure $function the closure to call if the file does not exist
@param bool $file returns the cache file or the file contents
@param bool $actual returns the actual cache file
@return string
@throws \InvalidArgumentException
Get or create the cache entry