1
0
Fork 0
php-language-server/src/Cache/ClientCache.php

45 lines
941 B
PHP
Raw Normal View History

2017-01-26 00:37:08 +00:00
<?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
{
/**
* @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): Promise
{
return $this->client->xcache->get($key)->then('unserialize')->otherwise(function () {});
}
/**
* Sets a value in the cache
*
* @param string $key
* @param mixed $value
* @return Promise
*/
public function set(string $key, $value): Promise
{
return $this->client->xcache->set($key, serialize($value))->otherwise(function () {});
}
}