Go\Instrument\ClassLoading\CachePathManager::queryCacheState PHP Method

queryCacheState() public method

Tries to return an information for queried resource
public queryCacheState ( string | null $resource = null ) : array | null
$resource string | null Name of the file or null to get all information
return array | null Information or null if no record in the cache
    public function queryCacheState($resource = null)
    {
        if (!$resource) {
            return $this->cacheState;
        }
        if (isset($this->newCacheState[$resource])) {
            return $this->newCacheState[$resource];
        }
        if (isset($this->cacheState[$resource])) {
            return $this->cacheState[$resource];
        }
        return null;
    }

Usage Example

 /**
  * This method may transform the supplied source and return a new replacement for it
  *
  * @param StreamMetaData $metadata Metadata for source
  * @return void|bool Return false if transformation should be stopped
  */
 public function transform(StreamMetaData $metadata)
 {
     // Do not create a cache
     if (!$this->cachePath) {
         return $this->processTransformers($metadata);
     }
     $originalUri = $metadata->uri;
     $wasProcessed = false;
     $cacheUri = $this->cacheManager->getCachePathForResource($originalUri);
     $lastModified = filemtime($originalUri);
     $cacheState = $this->cacheManager->queryCacheState($originalUri);
     $cacheModified = $cacheState ? $cacheState['filemtime'] : 0;
     if ($cacheModified < $lastModified || !$this->container->isFresh($cacheModified)) {
         $wasProcessed = $this->processTransformers($metadata);
         if ($wasProcessed) {
             $parentCacheDir = dirname($cacheUri);
             if (!is_dir($parentCacheDir)) {
                 mkdir($parentCacheDir, 0770, true);
             }
             file_put_contents($cacheUri, $metadata->source);
             if (!$cacheState && $this->cacheFileMode) {
                 chmod($cacheUri, $this->cacheFileMode);
             }
         }
         $this->cacheManager->setCacheState($originalUri, array('filemtime' => isset($_SERVER['REQUEST_TIME']) ? $_SERVER['REQUEST_TIME'] : time(), 'cacheUri' => $wasProcessed ? $cacheUri : null));
         return $wasProcessed;
     }
     if ($cacheState) {
         $wasProcessed = isset($cacheState['cacheUri']);
     }
     if ($wasProcessed) {
         $metadata->source = file_get_contents($cacheUri);
     }
     return $wasProcessed;
 }
All Usage Examples Of Go\Instrument\ClassLoading\CachePathManager::queryCacheState