Microweber\Utils\Adapters\Cache\Storage\FileStorage::get PHP Method

get() public method

Retrieve an item from the cache by key.
public get ( string $key ) : mixed
$key string
return mixed
    public function get($key)
    {
        $key = $this->appendLocale($key);
        if (!empty($this->tags)) {
            foreach ($this->tags as $tag) {
                if (in_array($tag, $this->deleted_tags)) {
                    // return;
                }
            }
        }
        if (!isset($this->memory[$key])) {
            $path = $this->path($key);
            if (!$this->files->exists($path)) {
                return;
            }
            try {
                $expire = substr($contents = @file_get_contents($path), 0, 10);
            } catch (\Exception $e) {
                return;
            }
            // If the current time is greater than expiration timestamps we will delete
            // the file and return null. This helps clean up the old files and keeps
            // this directory much cleaner for us as old files aren't hanging out.
            if (time() >= $expire) {
                return $this->forget($key);
            }
            if ($contents) {
                $this->memory[$key] = unserialize(substr($contents, 10));
            }
        }
        return $this->memory[$key];
    }

Usage Example

Beispiel #1
0
 /**
  * Retrieve an item from the cache by key.
  *
  * @param  string $key
  *
  * @return mixed
  */
 public function get($key)
 {
     return $this->adapter->get($key);
 }