-
Notifications
You must be signed in to change notification settings - Fork 187
Expand file tree
/
Copy pathClientCache.php
More file actions
51 lines (45 loc) Β· 1016 Bytes
/
ClientCache.php
File metadata and controls
51 lines (45 loc) Β· 1016 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
declare(strict_types=1);
namespace LanguageServer\Cache;
use LanguageServer\LanguageClient;
use Sabre\Event\Promise;
/**
* Caches content through a xcache/* requests
*/
class ClientCache implements Cache
{
/**
* @var LanguageClient
*/
public $client;
/**
* @param LanguageClient $client
*/
public function __construct(LanguageClient $client)
{
$this->client = $client;
}
/**
* Gets a value from the cache
*
* @param string $key
* @return Promise <mixed>
*/
public function get(string $key): \Generator
{
$cached = yield from $this->client->xcache->get($key);
$obj = unserialize($cached);
return $obj;
}
/**
* Sets a value in the cache
*
* @param string $key
* @param mixed $value
* @return Promise
*/
public function set(string $key, $value): \Generator
{
return yield from $this->client->xcache->set($key, serialize($value));
}
}