4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\Profiler;
14 @trigger_error('The '.__NAMESPACE__.'\MemcachedProfilerStorage class is deprecated since Symfony 2.8 and will be removed in 3.0. Use FileProfilerStorage instead.', E_USER_DEPRECATED);
17 * Memcached Profiler Storage.
19 * @author Andrej Hudec <pulzarraider@gmail.com>
21 * @deprecated Deprecated since Symfony 2.8, to be removed in Symfony 3.0.
22 * Use {@link FileProfilerStorage} instead.
24 class MemcachedProfilerStorage extends BaseMemcacheProfilerStorage
32 * Internal convenience method that returns the instance of the Memcached.
36 * @throws \RuntimeException
38 protected function getMemcached()
40 if (null === $this->memcached) {
41 if (!preg_match('#^memcached://(?(?=\[.*\])\[(.*)\]|(.*)):(.*)$#', $this->dsn, $matches)) {
42 throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use Memcached with an invalid dsn "%s". The expected format is "memcached://[host]:port".', $this->dsn));
45 $host = $matches[1] ?: $matches[2];
48 $memcached = new \Memcached();
50 // disable compression to allow appending
51 $memcached->setOption(\Memcached::OPT_COMPRESSION, false);
53 $memcached->addServer($host, $port);
55 $this->memcached = $memcached;
58 return $this->memcached;
62 * Set instance of the Memcached.
64 * @param \Memcached $memcached
66 public function setMemcached($memcached)
68 $this->memcached = $memcached;
74 protected function getValue($key)
76 return $this->getMemcached()->get($key);
82 protected function setValue($key, $value, $expiration = 0)
84 return $this->getMemcached()->set($key, $value, time() + $expiration);
90 protected function delete($key)
92 return $this->getMemcached()->delete($key);
98 protected function appendValue($key, $value, $expiration = 0)
100 $memcached = $this->getMemcached();
102 if (!$result = $memcached->append($key, $value)) {
103 return $memcached->set($key, $value, $expiration);