Cachearium\CacheAbstract::appendCallback PHP Method

appendCallback() public method

Callbacks are always called at runtime, their result is never cached at this level. You may cache it in the callback, of course.
public appendCallback ( callable $callback ) : boolean
$callback callable
return boolean
    public function appendCallback(callable $callback)
    {
        // @codeCoverageIgnoreStart
        if (!$this->enabled) {
            return false;
        }
        // @codeCoverageIgnoreEnd
        if (!$this->inloop) {
            return false;
        }
        $data = ob_get_contents();
        ob_clean();
        $this->loopdata[$this->inloop]->appendData($data);
        $this->loopdata[$this->inloop]->appendCallback($callback);
        return true;
    }

Usage Example

 protected function _startcallback(CacheAbstract $cache)
 {
     $key = new CacheKey("startcallback", 1);
     $cache->clean($key);
     $this->assertFalse($cache->start($key));
     echo "something ";
     $this->assertTrue($cache->appendCallback('callbackTesterStart'));
     echo " otherthing";
     $output = $cache->end(false);
     $this->assertContains(CALLBACKVALUE, $output);
     // run again, we should have another value
     $second = $cache->start($key, null, false);
     $this->assertNotFalse($second);
     $this->assertContains(CALLBACKVALUE, $second);
     $this->assertNotEquals($second, $output);
 }
All Usage Examples Of Cachearium\CacheAbstract::appendCallback