method getSet documentation in bbn\Cache

Returns the cache for the given item, but if expired or absent creates it before by running the provided function.

function(callable $fn, string $item, int $ttl = NULL) { switch (self::$type) { case 'apc': break; case 'memcache': break; case 'files': // Getting the data $tmp = $this->getRaw($item, $ttl); $data = null; // Can't get the data if (!$tmp) { $file = self::_file($item, $this->path); // Temporary file will be created to tell other processes the cache is being created $tmp_file = X::dirname($file).'/_'.X::basename($file); // Will become true if the cache should be created $do = false; // If the temporary file doesn't exist we create one if (!$this->fs->isFile($tmp_file)) { $this->fs->createPath(X::dirname($tmp_file)); $this->fs->putContents($tmp_file, ' '); // If the original file exists we delete it if ($this->fs->isFile($file)) { $this->fs->delete($file); } $timer = new Util\Timer(); $timer->start(); try { $data = $fn(); } catch (Exception $e) { unlink($tmp_file); throw $e; } $exec = $timer->stop(); $this->set($item, $data, $ttl, $exec); $this->fs->delete($tmp_file); } // Otherwise another process is certainly creating the cache, so wait for it else { return $this->get($item); } // Creating the cache } else { $data = $tmp['value']; } return $data; } }

Returns the cache for the given item, but if expired or absent creates it before by running the provided function. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.