update readme
This commit is contained in:
parent
bb13950966
commit
46b98d16a6
88 changed files with 7546 additions and 176 deletions
|
@ -3,14 +3,16 @@
|
|||
namespace Lubian\NoFramework\Repository;
|
||||
|
||||
use Lubian\NoFramework\Model\MarkdownPage;
|
||||
use Lubian\NoFramework\Settings;
|
||||
use Symfony\Contracts\Cache\CacheInterface;
|
||||
use Symfony\Contracts\Cache\ItemInterface;
|
||||
|
||||
class CachedMarkdownPageRepo implements MarkdownPageRepo
|
||||
{
|
||||
public function __construct(
|
||||
private CacheInterface $cache,
|
||||
private MarkdownPageRepo $repo,
|
||||
private readonly CacheInterface $cache,
|
||||
private readonly MarkdownPageRepo $repo,
|
||||
private readonly Settings $settings,
|
||||
) {
|
||||
}
|
||||
|
||||
|
@ -20,6 +22,9 @@ class CachedMarkdownPageRepo implements MarkdownPageRepo
|
|||
public function all(): array
|
||||
{
|
||||
$callback = fn () => $this->repo->all();
|
||||
if ($this->settings->isDev()) {
|
||||
return $callback();
|
||||
}
|
||||
return $this->cache->get('ALLPAGES', function (ItemInterface $item) use ($callback) {
|
||||
$item->expiresAfter(30);
|
||||
return $callback();
|
||||
|
@ -29,6 +34,9 @@ class CachedMarkdownPageRepo implements MarkdownPageRepo
|
|||
public function byId(int $id): MarkdownPage
|
||||
{
|
||||
$callback = fn () => $this->repo->byId($id);
|
||||
if ($this->settings->isDev()) {
|
||||
return $callback();
|
||||
}
|
||||
return $this->cache->get('PAGE' . $id, function (ItemInterface $item) use ($callback) {
|
||||
$item->expiresAfter(30);
|
||||
return $callback();
|
||||
|
@ -38,9 +46,17 @@ class CachedMarkdownPageRepo implements MarkdownPageRepo
|
|||
public function byTitle(string $title): MarkdownPage
|
||||
{
|
||||
$callback = fn () => $this->repo->byTitle($title);
|
||||
if ($this->settings->isDev()) {
|
||||
return $callback();
|
||||
}
|
||||
return $this->cache->get('PAGE' . $title, function (ItemInterface $item) use ($callback) {
|
||||
$item->expiresAfter(30);
|
||||
return $callback();
|
||||
});
|
||||
}
|
||||
|
||||
public function save(MarkdownPage $page): MarkdownPage
|
||||
{
|
||||
return $this->repo->save($page);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue