Elgg  Version 1.11
StashPool.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg\Cache;
3 
4 use Stash;
5 
17 final class StashPool implements Pool {
18 
20  private $stash;
21 
27  public function __construct(Stash\Pool $stash) {
28  $this->stash = $stash;
29  }
30 
32  public function get($key, callable $callback) {
33  assert(is_string($key) || is_int($key));
34 
35  $item = $this->stash->getItem((string)$key);
36 
37  $result = $item->get();
38 
39  if ($item->isMiss()) {
40  $item->lock();
41 
42  $result = call_user_func($callback);
43 
44  $this->stash->save($item->set($result));
45  }
46 
47  return $result;
48  }
49 
51  public function invalidate($key) {
52  assert(is_string($key) || is_int($key));
53 
54  $this->stash->getItem((string)$key)->clear();
55  }
56 
58  public function put($key, $value) {
59  assert(is_string($key) || is_int($key));
60 
61  $this->stash->getItem((string)$key)->set($value);
62  }
63 
69  public static function createEphemeral() {
70  return new self(new Stash\Pool(new Stash\Driver\Ephemeral()));
71  }
72 }
$value
Definition: longtext.php:26
put($key, $value)
Definition: StashPool.php:58
__construct(Stash\Pool $stash)
Constructor.
Definition: StashPool.php:27
$key
Definition: summary.php:34
$item
Definition: item.php:12
static createEphemeral()
Create an in-memory implementation of the pool.
Definition: StashPool.php:69