Get the stream data.

@param bool $cache Whether cache the stream data or not.
@return bool|string
@throws PdfTypeException
@throws CrossReferenceException
@throws PdfParserException
500350
public function getStream($cache = false)
    {
        if (\is_int($this->stream)) {
            $length = PdfDictionary::get($this->value, 'Length');
            if ($this->parser !== null) {
                $length = PdfType::resolve($length, $this->parser);
            }

            if (!($length instanceof PdfNumeric) || $length->value === 0) {
                $this->reader->reset($this->stream, 100000);
                $buffer = $this->extractStream();
            } else {
                $this->reader->reset($this->stream, $length->value);
                $buffer = $this->reader->getBuffer(false);
                if ($this->parser !== null) {
                    $this->reader->reset($this->stream + strlen($buffer));
                    $this->parser->getTokenizer()->clearStack();
                    $token = $this->parser->readValue();
                    if ($token === false || !($token instanceof PdfToken) || $token->value !== 'endstream') {
                        $this->reader->reset($this->stream, 100000);
                        $buffer = $this->extractStream();
                        $this->reader->reset($this->stream + strlen($buffer));
                    }
                }
            }

            if ($cache === false) {
                return $buffer;
            }

            $this->stream = $buffer;
            $this->reader = null;
        }

        return $this->stream;
    }
365259
public function getCache()
    {
        try {
            $handle = $this->handle;
            $result = $handle->prepare(
                'SELECT * FROM `' .
                $this->config['table'] .
                '` where type=?'
            );
            $result->execute(array($this->type));

            foreach ($result as $row) {
                return unserialize($row['data']);
            }

        } catch (\PDOException $e) {
            throw new \PDOException('PDOException: ' . $e->getMessage());
        }

        return false;
    }
261408
protected function loadFromCache()
    {
        $this->log->debug("Load from cache file {$this->filePath}");
        $data = $this->getDataFromFile();
        if ($data === false) {
            $data = '';
        }

        // validate data through parser
        if (!$this->isDataValid($data)) {
            $this->addError($this->filePath, 'Data not valid according to parser');

            return false;
        }

        // verify if local cache is expired
        if ($this->isCacheExpired()) {
            $this->addError($this->filePath, 'Local cache is expired');

            return false;
        }

        return true;
    }
582406
protected function getCache($key)
    {
        if (array_key_exists($key, $this->cache)) {
            return $this->cache[$key];
        }
        return false;
    }
177996
protected function _get()
	{
		// get the apc key for the cache identifier
		$key = $this->_get_key();

		// fetch the cached data from the apc store
		$payload = apc_fetch($key);

		try
		{
			$this->unprep_contents($payload);
		}
		catch (\UnexpectedValueException $e)
		{
			return false;
		}

		return true;
	}
706842
public function load($overwrite = false, $cache = true)
	{
		$paths = $this->find_file($cache);
		$config = array();

		foreach ($paths as $path)
		{
			$config = $overwrite ?
				array_merge($config, $this->load_file($path)) :
				\Arr::merge($config, $this->load_file($path));
		}

		return $config;
	}
210646
public static function fromCache($cache)
    {
        if (!is_object($cache)) {
            throw new InvalidArgumentException('Cache must be one of the known cache objects');
        }

        if ($cache instanceof CacheAdapterInterface) {
            return $cache;
        } elseif ($cache instanceof Cache) {
            return new DoctrineCacheAdapter($cache);
        } elseif ($cache instanceof StorageInterface) {
            return new Zf2CacheAdapter($cache);
        } else {
            throw new InvalidArgumentException('Unknown cache type: ' . get_class($cache));
        }
    }
683824
public function get($key, $timestamp = false)
    {
        if ($this->where == true) {
            $this->setCache($key)->setPath(CYGNITE_BASE.DS.toPath('public.storage.cache').DS);
        }

        $cached = [];
        $cached = $this->getCache();

        if ($timestamp === false) {
            return $cached[$key]['data'];
        } else {
            return $cached[$key]['time'];
        }
    }
406401
public static function getStream($data)
    {
        if (!self::$_id) {
            stream_wrapper_register(self::WRAPPER_NAME, __CLASS__);
        }

        return fopen(
            self::WRAPPER_NAME . '://' . ++self::$_id,
            'wb',
            false,
            stream_context_create(array(
                self::WRAPPER_NAME => array(
                    'data' => $data
                )
            ))
        );
    }
862103
public function getStream($context = null)
	{
		if (is_string($this->content)) {
			$stream = fopen('php://memory', 'r+');
			fwrite($stream, $this->content);
			rewind($stream);
			return $stream;
		}
		$fn = $this->streamFn;
		return $fn($context);
	}
349924
public function read($key)
    {
        if (!isset($this->cacheDirectory)) {
            return;
        }

        $this->loadCacheMetaData();

        return unserialize(file_get_contents($this->cacheDirectory . '/' . $key));
    }
1222651
public function render($cache = false, $params = array())
	{
		\App::get('response')->headers->set('Cache-Control', 'no-cache', false);
		\App::get('response')->headers->set('Pragma', 'no-cache');
		\App::get('response')->headers->set('Content-disposition', 'attachment; filename="' . $this->getName() . '.json"', true);

		parent::render();

		return $this->getBuffer();
	}
1266721
public function cache($cache = null)
    {
        if ($cache === null) {
            return $this->_cache;
        }

        if ($cache === false) {
            $this->_cache = false;

            return $this;
        }

        if ($cache === true) {
            $cache = 'cake_pdf';
        }

        if (!in_array($cache, Cache::configured())) {
            throw new Exception(sprintf('CakePdf cache is not configured: %s', $cache));
        }

        $this->_cache = $cache;

        return $this;
    }
963525
public function get($key)
    {
        $filePath = $this->getFilePathFromKey($key);

        if (!file_exists($filePath)) {
            return false;
        }

        if (!is_readable($filePath)) {
            return false;
        }

        $cacheFileData = file_get_contents($filePath);

        if ($this->config['gzipCompression']) {
            try {
                $cacheFileData = gzuncompress($cacheFileData);
            } catch (\Exception $e) {
                $cacheFileData = false;
            }
        }

        // Bail immediately if the file could not be read, or its data could not be uncompressed
        if (!$cacheFileData) {
            return false;
        }

        $cacheObj = json_decode($cacheFileData);

        // Unable to decode JSON
        if ($cacheObj === null) {
            return false;
        }

        // Check cache object format
        if (!isset($cacheObj->content) || !isset($cacheObj->expiryTimestamp)) {
            return false;
        }

        // Check cache content is serialized
        if (!$this->isSerialized($cacheObj->content)) {
            return false;
        }

        if (!function_exists('sys_getloadavg') && $this->config['unixLoadUpperThreshold'] !== -1) {
            throw new Exception('Your PHP installation does not support `sys_getloadavg` (Windows?). Please set `unixLoadUpperThreshold` to `-1` in your DOFileCache config.');
        }

        if ($this->config['unixLoadUpperThreshold'] == -1) {
            $unixLoad = [0 => -PHP_INT_MAX, 1 => -PHP_INT_MAX, 2 => -PHP_INT_MAX];
        } else {
            $unixLoad = sys_getloadavg();
        }

        if ($cacheObj->expiryTimestamp > time() || $unixLoad[0] >= $this->config['unixLoadUpperThreshold']) {
            // Cache item has not yet expired or system load is too high
            return unserialize($cacheObj->content);
        } else {
            // Cache item has expired
            return false;
        }
    }
998605
public function execute($cache = true) {
        // @todo Execute sql here
        if (strlen($this->_sql_query)) {
            // Get cache key
            $cache_key = sha1($this->_sql_query);
            
            // If cache exists and cache is enable
            $config = Config::get('db');
            $cache_enable = isset($config->cache) ? $config->cache : false;
            $cache_time = isset($config->cache_time) ? $config->cache_time : 1440;
            
            if ($cache_enable) {
                if (Cache::exists($cache_key) && $cache) {
                    return Cache::get($cache_key);
                }
            }
            
            // Return contents
            $results = [];

            // Open connection
            if (is_null($this->db) ||
                ($this->db instanceof \mysqli && !$this->db->ping())) {
                $this->__connect();
            }

            // Execute command
            $return = $this->db->query($this->_sql_query);
            
            // Close connection
            $thread = $this->db->thread_id;
            $this->db->close();
            $this->db->kill($thread);
            
            // Log executed query
            array_push(self::$_last_commands, $this->_sql_query);
        
            
            if (is_object($return) && isset($return->num_rows)) {
                while ($row = $return->fetch_array()) {
                    array_push($results, $row);
                }
                
                // Save cache (overwrites existing)
                if ($cache) {
                    Cache::save($cache_key, $results, true, $cache_time);
                }
                
                return $results;
            }
            
            return $return;
        }
    }
979478
private function loadCache()
    {
        if (!is_null($this->cache)) {
            return $this->cache;
        }

        if (file_exists($this->getCacheFile()) && !empty($this->getCacheFile())) {
            $this->cache = json_decode(file_get_contents($this->getCacheFile()), true);
            return $this->cache;
        }
        return null;
    }
434665
public static function get($id, $cache = true) {
        if (!$id) {
            return null;
        }
        $model = get_called_class();
        $db_cache = null;
        if ($cache) {
            /* @var $db_cache DBCache */
            $db_cache = Ioc::get(DBCache::class);
            $data = $db_cache->recordCache($model, $id);
            if ($data) {
                return $data;
            }
        }
        /* @var $model Record */
        $model = new $model;
        $pk = $model->getPkField();
        $where[ $pk ] = $id;
        $data = $model::find($where);
        if ($cache && $data) {
            $db_cache->recordCacheSave(get_called_class(), $id, $data->_db_data);
        }
        return $data;
    }