Load a cache, this does the generic post-processing

@return  bool  success
427237
protected function _get()
	{
		$id_path = $this->identifier_to_path( $this->identifier );
		$file = static::$path.$id_path.'.cache';
		if ( ! is_file($file) or ($size = filesize($file)) == 0)
		{
			return false;
		}

		$handle = fopen($file, 'r');
		if ( ! $handle)
		{
			return false;
		}

		// wait for a lock
		while( ! flock($handle, LOCK_SH));

		// read the session data
		$payload = fread($handle, $size);

		//release the lock
		flock($handle, LOCK_UN);

		// close the file
		fclose($handle);

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

		return true;
	}
186789
public function process()
    {
        if ($this->cache !== null) {
            return $this->cache;
        } else {
            return ($this->cache = UriTemplate::expand($this->template, $this->data));
        }
    }
1259768
public function load(): void
    {
        try {
            $keys = $this->cache->get(self::INDEXING_KEY);
            if ($keys instanceof Keys) {
                $this->keys = $keys;
                return;
            }
        } catch (CacheException $e) {
            trigger_error($e->getMessage(), E_USER_WARNING);
        }

        $this->keys = new Keys();
    }
122804
protected function loadAndCacheFaces(){

        $faces = $this->_loadFaces();
        foreach($faces as $face){
            $this->cacheFace($face);
            $this->addFace($face);
        }
    }
567287
public function load()
    {
        if (null === $this->loaded) {
            return;
        }

        $this->loaded = null;

        /** @var $cache StorageInterface */
        $cache      = $this->serviceLocator->get('BjyAuthorize\Cache');

        /** @var $cacheKeyGenerator callable */
        $cacheKeyGenerator  = $this->serviceLocator->get('BjyAuthorize\CacheKeyGenerator');
        $cacheKey           = $cacheKeyGenerator();

        $success    = false;
        $this->acl  = $cache->getItem($cacheKey, $success);

        if (!($this->acl instanceof Acl) || !$success) {
            $this->loadAcl();
            $cache->setItem($cacheKey, $this->acl);
        }

        $this->setIdentityProvider($this->serviceLocator->get('BjyAuthorize\Provider\Identity\ProviderInterface'));

        $parentRoles = $this->getIdentityProvider()->getIdentityRoles();

        $this->acl->addRole($this->getIdentity(), $parentRoles);
    }
806498
public function getCache()
    {
        // make sure filters are parsed again if cache expired
        if (!$this->isValidFile($this->path)) {
            return false;
        }

        $data = unserialize(file_get_contents($this->path));

        return $data;
    }
519483
private function _populate_cache()
    {
        if ($this->_use_json) {
            if (is_readable($this->_cache_file) &&
            ($loaded = @json_decode(Common::getContents($this->_cache_file, ''), true)) && is_array($loaded)) {
                $this->_existing_cache_vals = $loaded;
            }
        } else {
            if (is_readable($this->_cache_file) &&
            ($loaded = @unserialize(Common::getContents($this->_cache_file, false))) && is_array($loaded)) {
                $this->_existing_cache_vals = $loaded;
            }
        }
    }
359510
function load( $flush = false ) {
            $this->_logger->entrance();

            $option_name = $this->get_option_manager_name();

            if ( $flush || ! isset( $this->_options ) ) {
                if ( isset( $this->_options ) ) {
                    // Clear prev options.
                    $this->clear();
                }

                $cache_group = $this->get_cache_group();

                if ( ! WP_FS__DEBUG_SDK ) {

                    $this->_options = wp_cache_get(
                        $option_name,
                        $cache_group
                    );
                }

                $cached = true;

                if ( empty( $this->_options ) ) {
                    if ( $this->_is_network_storage ) {
                        $this->_options = get_site_option( $option_name );
                    } else if ( $this->_blog_id > 0 ) {
                        $this->_options = get_blog_option( $this->_blog_id, $option_name );
                    } else {
                        $this->_options = get_option( $option_name );
                    }

                    if ( is_string( $this->_options ) ) {
                        $this->_options = json_decode( $this->_options );
                    }

//					$this->_logger->info('get_option = ' . var_export($this->_options, true));

                    if ( false === $this->_options ) {
                        $this->clear();
                    }

                    $cached = false;
                }

                if ( ! WP_FS__DEBUG_SDK && ! $cached ) {
                    // Set non encoded cache.
                    wp_cache_set( $option_name, $this->_options, $cache_group );
                }
            }
        }
169159
private function load()
    {
        $filename = $this->path . '/domainparsertld.txt';

        if (file_exists($filename)) {
            $this->tldList = unserialize(file_get_contents($filename));

            // will reload tld list if timestamp of cache file is outdated
            if (time() - $this->tldList['timestamp'] > $this->cacheTime) {
                $this->reload = true;
            }

            // will reload tld list if changes to Additional.php have been made
            if ($this->tldList['timestamp'] < filemtime(__DIR__ .'/Additional.php')) {
                $this->reload = true;
            }
        }

        // check connection - if there is no internet connection skip loading
        $existFile = file_exists($filename);

        if (! $existFile || $this->reload === true) {
            $this->catchTlds($existFile);
            $file = fopen($filename, 'w+');

            if ($file === false) {
                throw AbstractException::factory('OpenFile', 'Could not open cache file.');
            }

            if (fwrite($file, serialize($this->tldList)) === false) {
                throw AbstractException::factory('WriteFile', 'Could not open cache file for writing.');
            }

            fclose($file);
        }

        $this->loaded = true;
    }
517972
public function loadCache($cacheKey)
    {
        if (!isset($this->localCache[$cacheKey])) {
            $data = $this->cache->load($cacheKey);

            if ($data) {
                $data = unserialize($data);
            }

            $this->localCache[$cacheKey] = $data;
        }

        return $this->localCache[$cacheKey];
    }
450129
public function load()
    {
        if ($this->isLoaded && isset($this->blockCache[$this->getCacheKey()])) {
            return;
        }

        $blocks = $this->getBlocksRecursive($this->object);

        $blocks = $this->blockManager->sortBlocks($blocks);
        $cacheKey = $this->getCacheKey();

        $blocks = $this->loadSharedBlocks($blocks);

        $this->blockCache[$cacheKey] = $blocks;

        $this->isLoaded = true;

        return $this;
    }
20453
public function preLoad()
    {

        $query = new Query( <<<SQL
SELECT
    n.nspname "schema",
    c.relname "name",
    string_to_array(
        indrelid::text || '.' || replace( indkey::text, ' ', ' ' || indrelid::text || '.' ),
        ' '
    ) AS columns,
    false "inherited",
    i.*,
    string_to_array( indkey::text, ' ' )::int[] as indkey
FROM
    pg_index i
INNER JOIN
    pg_class c ON i.indexrelid = c.oid
LEFT JOIN
    pg_namespace n ON n.oid = c.relnamespace
WHERE
    n.nspname NOT IN ('pg_catalog', 'pg_toast', 'information_schema')
SQL
        );

        $datas = $this->db->query( $query )->fetch( Result::TYPE_DETECT );
        parent::cacheInvalidate();
        $this->initByDatas( $datas );

    }
682474
public function __load()
    {
        if (! file_exists($file = $this->getDatabaseFileName())) {
            return collect();
        }

        return collect(json_decode(file_get_contents($file), true));
    }
419275
public function load()
    {
        // Initial state, is always empty array
        $data = array();

        // Alter $data in case it exists and its valid
        if ($this->storageAdapter->has($this->key)) {
            $target = $this->serializer->unserialize($this->storageAdapter->get($this->key));

            // If $target is null, then data either is damaged or doesn't exist, otherwise it's okay
            if ($target !== null) {
                $data = $target;
            }
        }

        return $data;
    }
279626
private function _process() {

        // if caching is enabled but path doesn't exist, or is not writable
        if ($this->cache !== false && (!is_dir($this->cache['path']) || !is_writable($this->cache['path'])))

            // trigger an error and stop execution
            trigger_error('Cache path does not exists or is not writable', E_USER_ERROR);

        // iterate through the requests to process
        foreach ($this->_requests as $index => $request) {

            // if callback function is defined but it doesn't exists
            if ($request['callback'] != '' && !is_callable($request['callback']))

                // trigger an error and stop execution
                // the check is for when callback functions are defined as methods of a class
                trigger_error('Callback function "' . (is_array($request['callback']) ? array_pop($request['callback']) : $request['callback']) . '" does not exist', E_USER_ERROR);

            // if caching is enabled
            if ($this->cache !== false) {

                // get the name to be used for the cache file associated with the request
                $cache_file = $this->_get_cache_file_name($request);

                // if cache file exists and is not expired
                if (file_exists($cache_file) && filemtime($cache_file) + $this->cache['lifetime'] > time()) {

                    // if we have a callback
                    if ($request['callback'] != '') {

                        // prepare the arguments to pass to the callback function
                        $arguments = array_merge(

                            // made of the result from the cache file...
                            array(unserialize($this->cache['compress'] ? gzuncompress(file_get_contents($cache_file)) : file_get_contents($cache_file))),

                            // ...and any additional arguments (minus the first 2)
                            (array)$request['arguments']

                        );

                        // feed them as arguments to the callback function
                        call_user_func_array($request['callback'], $arguments);

                        // remove this request from the list so it doesn't get processed
                        unset($this->_requests[$index]);

                    }

                }

            }

        }

        // if there are any requests to process
        if (!empty($this->_requests)) {

            // initialize the multi handle
            // this will allow us to process multiple handles in parallel
            $this->_multi_handle = curl_multi_init();

            // queue the first batch of requests
            // (as many as defined by the "threads" property, or less if there aren't as many requests)
            $this->_queue_requests();

            // a flag telling the library if there are any requests currently processing
            $running = null;

            // loop
            do {

                // get status update
                while (($status = curl_multi_exec($this->_multi_handle, $running)) == CURLM_CALL_MULTI_PERFORM);

                // if no request has finished yet, keep looping
                if ($status != CURLM_OK) break;

                // if a request was just completed, we'll have to find out which one
                while ($info = curl_multi_info_read($this->_multi_handle)) {

                    // get handle of the completed request
                    $handle = $info['handle'];

                    // get content associated with the handle
                    $content = curl_multi_getcontent($handle);

                    // get the handle's ID
                    $resource_number = preg_replace('/Resource id #/', '', $handle);

                    // get the information associated with the request
                    $request = $this->_running['fh' . $resource_number];

                    // create a new object in which we will store all the data associated with the handle,
                    // as properties of this object
                    $result = new stdClass();

                    // get information about the request
                    $result->info = curl_getinfo($handle);

                    // extend the "info" property with the original URL
                    $result->info = array('original_url' => $request['url']) + $result->info;

                    // if request was a POST
                    if (isset($request['options'][CURLOPT_POSTFIELDS]) && $request['options'][CURLOPT_POSTFIELDS])

                        // put POST parameters in the response
                        $result->post = $request['options'][CURLOPT_POSTFIELDS];

                    // last request headers
                    $result->headers['last_request'] =

                        (

                            // if CURLINFO_HEADER_OUT is set
                            isset($request['options'][CURLINFO_HEADER_OUT]) &&

                            // if CURLINFO_HEADER_OUT is TRUE
                            $request['options'][CURLINFO_HEADER_OUT] == 1 &&

                            // if we actually have this information
                            isset($result->info['request_header'])

                        // extract request headers
                        ) ? $this->_parse_headers($result->info['request_header'], true) : '';

                    // remove request headers information from its previous location
                    unset($result->info['request_header']);

                    // get headers (unless we were explicitly told not to)
                    $result->headers['responses'] = (isset($request['options'][CURLOPT_HEADER]) && $request['options'][CURLOPT_HEADER] == 1) ?

                        $this->_parse_headers(substr($content, 0, $result->info['header_size'])) :

                        '';

                    // get output (unless we were explicitly told not to)
                    $result->body = !isset($request['options'][CURLOPT_NOBODY]) || $request['options'][CURLOPT_NOBODY] == 0 ?

                        (isset($request['options'][CURLOPT_HEADER]) && $request['options'][CURLOPT_HEADER] == 1 ?

                        substr($content, $result->info['header_size']) :

                        $content) :

                        '';

                    // if _htmlentities is set to TRUE, we're not doing a binary transfer and we have a body, run htmlentities() on it
                    if ($this->_htmlentities && !isset($request['options'][CURLOPT_BINARYTRANSFER]) && $result->body != '') {

                        // since PHP 5.3.0, htmlentities will return an empty string if the input string contains an
                        // invalid code unit sequence within the given encoding (utf-8 in our case)
                        // so take care of that
                        if (defined(ENT_IGNORE)) $result->body = htmlentities($result->body, ENT_IGNORE, 'utf-8');

                        // for PHP versions lower than 5.3.0
                        else htmlentities($result->body);

                    }

                    // get CURLs response code and associated message
                    $result->response = array($this->_response_messages[$info['result']], $info['result']);

                    // if we have a callback
                    if (isset($request['callback']) && $request['callback'] != '') {

                        // prepare the arguments to pass to the callback function
                        $arguments = array_merge(

                            // made of the "result" object...
                            array($result),

                            // ...and any additional arguments
                            $request['arguments']

                        );

                        // if downloaded a file
                        if (isset($request['options'][CURLOPT_BINARYTRANSFER]) && $request['options'][CURLOPT_BINARYTRANSFER]) {

                            // we make a dummy array with the first first 2 elements (which we also remove from the $arguments[0]->info array)
                            $tmp_array = array_splice($arguments[0]->info, 0, 2);

                            // make available the name we saved the file with
                            // (we need to merge the first 2 elements, our new array and the rest of the elements)
                            $arguments[0]->info = array_merge($tmp_array, array('downloaded_filename' => $this->_running['fh' . $resource_number]['file_name']), $arguments[0]->info);

                        }

                        // feed them as arguments to the callback function
                        // and save the callback's response, if any
                        $callback_response = call_user_func_array($request['callback'], $arguments);

                    // if no callback function, we assume the response is TRUE
                    } else $callback_response = true;

                    // if caching is enabled and the callback function did not return FALSE
                    if ($this->cache !== false && $callback_response !== false) {

                        // get the name of the cache file associated with the request
                        $cache_file = $this->_get_cache_file_name($request);

                        // cache the result
                        file_put_contents($cache_file, $this->cache['compress'] ? gzcompress(serialize($result)) : serialize($result));

                        // set rights on the file
                        chmod($cache_file, intval($this->cache['chmod'], 8));

                    }

                    // if there are more URLs to process and we're don't pause between batches of requests, queue the next one(s)
                    if (!empty($this->_requests) && !$this->pause_interval) $this->_queue_requests();

                    // remove the handle that we finished processing
                    // this needs to be done *after* we've already queued a new URL for processing
                    curl_multi_remove_handle($this->_multi_handle, $handle);

                    // make sure the handle gets closed
                    curl_close($handle);

                    // if we downloaded a file
                    if (isset($request['options'][CURLOPT_BINARYTRANSFER]) && $request['options'][CURLOPT_BINARYTRANSFER])

                        // close the associated file pointer
                        fclose($this->_running['fh' . $resource_number]['file_handler']);

                    // we don't need the information associated with this request anymore
                    unset($this->_running['fh' . $resource_number]);

                }

                // waits until curl_multi_exec() returns CURLM_CALL_MULTI_PERFORM or until the timeout, whatever happens first
                // call usleep() if a select returns -1 - workaround for PHP bug: https://bugs.php.net/bug.php?id=61141
                if ($running && curl_multi_select($this->_multi_handle) === -1) usleep(100);

            // as long as there are threads running or requests waiting in the queue
            } while ($running || !empty($this->_running));

            // close the multi curl handle
            curl_multi_close($this->_multi_handle);

        }

    }
739366
protected function useCache()
    {
        // Should we use a cached version?
        if ($this->cache && $this->cacheExists()) {
            $this->templateOutput = $this->getCache();
            if ($this->templateOutput !== false) {
                return true;
            }
        }
        return false;
    }
1046461
public function loadAssoc()
	{
		$this->connect();

		$ret = null;

		// Execute the query and get the result set cursor.
		if (!($cursor = $this->execute()))
		{
			return;
		}

		// Get the first row from the result set as an associative array.
		$array = $this->fetchAssoc($cursor);

		if ($array)
		{
			$ret = $array;
		}

		// Free up system resources and return.
		$this->freeResult($cursor);

		return $ret;
	}