Skip to content

Commit

Permalink
OutputHelper: added rollback()
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 16, 2020
1 parent a82655d commit 3d063c9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Caching/OutputHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,14 @@ public function end(array $dependencies = []): void
$this->cache->save($this->key, ob_get_flush(), $dependencies + $this->dependencies);
$this->cache = null;
}


/**
* Stops and throws away the output.
*/
public function rollback(): void
{
ob_end_flush();
$this->cache = null;
}
}
11 changes: 11 additions & 0 deletions tests/Storages/FileStorage.start.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,14 @@ Assert::same('Hello', $cache->load('key'));
ob_start();
Assert::null($cache->start('key'));
Assert::same('Hello', ob_get_clean());



ob_start();
$block = $cache->start('key2');
Assert::type(Nette\Caching\OutputHelper::class, $block);
echo 'Hello';
$block->rollback();
Assert::same('Hello', ob_get_clean());

Assert::same(null, $cache->load('key2'));

0 comments on commit 3d063c9

Please sign in to comment.