4 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16 * This software consists of voluntary contributions made by many individuals
17 * and is licensed under the MIT license. For more information, see
18 * <http://www.doctrine-project.org>.
21 namespace Doctrine\Common\Cache;
26 * Memcache cache provider.
28 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
29 * @link www.doctrine-project.org
31 * @author Benjamin Eberlei <kontakt@beberlei.de>
32 * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
33 * @author Jonathan Wage <jonwage@gmail.com>
34 * @author Roman Borschel <roman@code-factory.org>
35 * @author David Abdemoulaie <dave@hobodave.com>
37 class MemcacheCache extends CacheProvider
45 * Sets the memcache instance to use.
47 * @param Memcache $memcache
49 public function setMemcache(Memcache $memcache)
51 $this->memcache = $memcache;
55 * Gets the memcache instance used by the cache.
59 public function getMemcache()
61 return $this->memcache;
67 protected function doFetch($id)
69 return $this->memcache->get($id);
75 protected function doContains($id)
77 return (bool) $this->memcache->get($id);
83 protected function doSave($id, $data, $lifeTime = 0)
85 if ($lifeTime > 30 * 24 * 3600) {
86 $lifeTime = time() + $lifeTime;
88 return $this->memcache->set($id, $data, 0, (int) $lifeTime);
94 protected function doDelete($id)
96 return $this->memcache->delete($id);
102 protected function doFlush()
104 return $this->memcache->flush();
110 protected function doGetStats()
112 $stats = $this->memcache->getStats();
114 Cache::STATS_HITS => $stats['get_hits'],
115 Cache::STATS_MISSES => $stats['get_misses'],
116 Cache::STATS_UPTIME => $stats['uptime'],
117 Cache::STATS_MEMORY_USAGE => $stats['bytes'],
118 Cache::STATS_MEMORY_AVAILIABLE => $stats['limit_maxbytes'],