Skip to content

Commit

Permalink
Add setCache method to LoaderInterface
Browse files Browse the repository at this point in the history
Every loader should accept a cache implementation that it will use to
cache loaded resources. And also make it chainable.
  • Loading branch information
otsch committed Feb 5, 2023
1 parent 3a6f440 commit 5dd6505
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Loader/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,16 @@ public function afterLoad(callable $callback): void
$this->addHookCallback('afterLoad', $callback);
}

public function setCache(CacheInterface $cache): void
public function setCache(CacheInterface $cache): static
{
$this->cache = $cache;

return $this;
}

public function userAgent(): UserAgentInterface
{
return $this->userAgent;
}

/**
Expand Down Expand Up @@ -92,11 +99,6 @@ protected function callHook(string $hook, mixed ...$arguments): void
}
}

public function userAgent(): UserAgentInterface
{
return $this->userAgent;
}

protected function logger(): LoggerInterface
{
return $this->logger;
Expand Down
6 changes: 6 additions & 0 deletions src/Loader/LoaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Crwlr\Crawler\Loader\Http\Exceptions\LoadingException;
use InvalidArgumentException;
use Psr\SimpleCache\CacheInterface;

interface LoaderInterface
{
Expand All @@ -21,4 +22,9 @@ public function load(mixed $subject): mixed;
* @throws LoadingException Throw one when loading failed.
*/
public function loadOrFail(mixed $subject): mixed;

/**
* Add an implementation of the PSR-16 CacheInterface that the Loader will use to cache loaded resources.
*/
public function setCache(CacheInterface $cache): static;
}

0 comments on commit 5dd6505

Please sign in to comment.