Skip to content

Commit

Permalink
Cache::start() renamed to capture()
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Dec 30, 2020
1 parent 5ffe263 commit 60281ab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
11 changes: 10 additions & 1 deletion src/Caching/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public function wrap(callable $function, array $dependencies = null): \Closure
* Starts the output cache.
* @param mixed $key
*/
public function start($key): ?OutputHelper
public function capture($key): ?OutputHelper
{
$data = $this->load($key);
if ($data === null) {
Expand All @@ -314,6 +314,15 @@ public function start($key): ?OutputHelper
}


/**
* @deprecated use capture()
*/
public function start($key): ?OutputHelper
{
return $this->capture($key);
}


/**
* Generates internal cache key.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* Test: Nette\Caching\Storages\FileStorage start().
* Test: Nette\Caching\Storages\FileStorage capture().
*/

declare(strict_types=1);
Expand All @@ -18,27 +18,27 @@ $cache = new Cache(new FileStorage(getTempDir()));


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


Assert::same('Hello', $cache->load('key'));


ob_start();
Assert::null($cache->start('key'));
Assert::null($cache->capture('key'));
Assert::same('Hello', ob_get_clean());



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

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

0 comments on commit 60281ab

Please sign in to comment.