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__.'\MemcacheProfilerStorage class is deprecated since Symfony 2.8 and will be removed in 3.0. Use FileProfilerStorage instead.', E_USER_DEPRECATED);
17 * Memcache 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 MemcacheProfilerStorage extends BaseMemcacheProfilerStorage
32 * Internal convenience method that returns the instance of the Memcache.
36 * @throws \RuntimeException
38 protected function getMemcache()
40 if (null === $this->memcache) {
41 if (!preg_match('#^memcache://(?(?=\[.*\])\[(.*)\]|(.*)):(.*)$#', $this->dsn, $matches)) {
42 throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use Memcache with an invalid dsn "%s". The expected format is "memcache://[host]:port".', $this->dsn));
45 $host = $matches[1] ?: $matches[2];
48 $memcache = new \Memcache();
49 $memcache->addServer($host, $port);
51 $this->memcache = $memcache;
54 return $this->memcache;
58 * Set instance of the Memcache.
60 * @param \Memcache $memcache
62 public function setMemcache($memcache)
64 $this->memcache = $memcache;
70 protected function getValue($key)
72 return $this->getMemcache()->get($key);
78 protected function setValue($key, $value, $expiration = 0)
80 return $this->getMemcache()->set($key, $value, false, time() + $expiration);
86 protected function delete($key)
88 return $this->getMemcache()->delete($key);
94 protected function appendValue($key, $value, $expiration = 0)
96 $memcache = $this->getMemcache();
98 if (method_exists($memcache, 'append')) {
100 if (!$result = $memcache->append($key, $value, false, $expiration)) {
101 return $memcache->set($key, $value, false, $expiration);
107 // simulate append in Memcache <3.0
108 $content = $memcache->get($key);
110 return $memcache->set($key, $content.$value, false, $expiration);