forked from zarincheg/telegram-bot-dialogs
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from koot-labs/laravel-cache
Use Laravel Cache and PSR-16 (Remove custom Store interface and implementations)
- Loading branch information
Showing
9 changed files
with
76 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace KootLabs\TelegramBotDialogs; | ||
|
||
use Psr\SimpleCache\CacheInterface; | ||
|
||
/** @api */ | ||
final class DialogRepository | ||
{ | ||
private CacheInterface $cache; | ||
private string $prefix; | ||
|
||
public function __construct(CacheInterface $cache, string $prefix = '') | ||
{ | ||
$this->cache = $cache; | ||
$this->prefix = $prefix; | ||
} | ||
|
||
public function put(string $key, Dialog $dialog, \DateTime | int $seconds): void | ||
{ | ||
$this->cache->set($this->prefixKey($key), serialize($dialog), $seconds); | ||
} | ||
|
||
public function has(string $key): bool | ||
{ | ||
return $this->cache->has($this->prefixKey($key)); | ||
} | ||
|
||
public function get(string $key): Dialog | ||
{ | ||
return unserialize($this->cache->get($this->prefixKey($key)), ['allowed_classes' => true]); | ||
} | ||
|
||
public function forget(string $key): bool | ||
{ | ||
return $this->cache->delete($this->prefixKey($key)); | ||
} | ||
|
||
private function prefixKey(string $key): string | ||
{ | ||
return "{$this->prefix}{$key}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.