123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace Elgg\Cache;
- use Stash;
- final class StashPool implements Pool {
-
- private $stash;
-
- public function __construct(Stash\Pool $stash) {
- $this->stash = $stash;
- }
-
- public function get($key, callable $callback) {
- assert(is_string($key) || is_int($key));
- $item = $this->stash->getItem((string)$key);
- $result = $item->get();
- if ($item->isMiss()) {
- $item->lock();
- $result = call_user_func($callback);
- $this->stash->save($item->set($result));
- }
- return $result;
- }
-
- public function invalidate($key) {
- assert(is_string($key) || is_int($key));
-
- $this->stash->getItem((string)$key)->clear();
- }
-
-
- public function put($key, $value) {
- assert(is_string($key) || is_int($key));
- $this->stash->getItem((string)$key)->set($value);
- }
-
-
- public static function createEphemeral() {
- return new self(new Stash\Pool(new Stash\Driver\Ephemeral()));
- }
- }
|