Skip to content
Browse files

Replace Common Cache with doctrine/cache package using Composer

  • Loading branch information...
1 parent 18b2c6e commit 0e178880c4eb8b6131e98c7a410b7a05a0574943 @beberlei beberlei committed
Showing with 65 additions and 2,280 deletions.
  1. +2 −1 composer.json
  2. +63 −1 composer.lock
  3. +0 −93 lib/Doctrine/Common/Cache/ApcCache.php
  4. +0 −96 lib/Doctrine/Common/Cache/ArrayCache.php
  5. +0 −102 lib/Doctrine/Common/Cache/Cache.php
  6. +0 −231 lib/Doctrine/Common/Cache/CacheProvider.php
  7. +0 −123 lib/Doctrine/Common/Cache/CouchbaseCache.php
  8. +0 −132 lib/Doctrine/Common/Cache/FileCache.php
  9. +0 −114 lib/Doctrine/Common/Cache/FilesystemCache.php
  10. +0 −121 lib/Doctrine/Common/Cache/MemcacheCache.php
  11. +0 −124 lib/Doctrine/Common/Cache/MemcachedCache.php
  12. +0 −108 lib/Doctrine/Common/Cache/PhpFileCache.php
  13. +0 −119 lib/Doctrine/Common/Cache/RedisCache.php
  14. +0 −93 lib/Doctrine/Common/Cache/WinCacheCache.php
  15. +0 −110 lib/Doctrine/Common/Cache/XcacheCache.php
  16. +0 −84 lib/Doctrine/Common/Cache/ZendDataCache.php
  17. +0 −20 tests/Doctrine/Tests/Common/Cache/ApcCacheTest.php
  18. +0 −21 tests/Doctrine/Tests/Common/Cache/ArrayCacheTest.php
  19. +0 −103 tests/Doctrine/Tests/Common/Cache/CacheTest.php
  20. +0 −47 tests/Doctrine/Tests/Common/Cache/CouchbaseCacheTest.php
  21. +0 −97 tests/Doctrine/Tests/Common/Cache/FilesystemCacheTest.php
  22. +0 −45 tests/Doctrine/Tests/Common/Cache/MemcacheCacheTest.php
  23. +0 −48 tests/Doctrine/Tests/Common/Cache/MemcachedCacheTest.php
  24. +0 −149 tests/Doctrine/Tests/Common/Cache/PhpFileCacheTest.php
  25. +0 −30 tests/Doctrine/Tests/Common/Cache/RedisCacheTest.php
  26. +0 −20 tests/Doctrine/Tests/Common/Cache/WinCacheCacheTest.php
  27. +0 −20 tests/Doctrine/Tests/Common/Cache/XcacheCacheTest.php
  28. +0 −28 tests/Doctrine/Tests/Common/Cache/ZendDataCacheTest.php
View
3 composer.json
@@ -14,7 +14,8 @@
],
"require": {
"php": ">=5.3.2",
- "doctrine/inflector": "1.*"
+ "doctrine/inflector": "1.*",
+ "doctrine/cache": "1.*"
},
"autoload": {
"psr-0": { "Doctrine\\Common\\": "lib/" }
View
64 composer.lock
@@ -1,7 +1,69 @@
{
- "hash": "af304c64e37f2f96cc10b7d1f8bfa3d9",
+ "hash": "369123de393e5e6f84fc0ebfd00adaac",
"packages": [
{
+ "name": "doctrine/cache",
+ "version": "v1.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/doctrine/cache.git",
+ "reference": "v1.0"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://github.com/doctrine/cache/archive/v1.0.zip",
+ "reference": "v1.0",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.2"
+ },
+ "time": "2013-01-10 22:43:46",
+ "type": "library",
+ "installation-source": "dist",
+ "autoload": {
+ "psr-0": {
+ "Doctrine\\Common\\Cache\\": "lib/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Jonathan Wage",
+ "email": "jonwage@gmail.com",
+ "homepage": "http://www.jwage.com/"
+ },
+ {
+ "name": "Guilherme Blanco",
+ "email": "guilhermeblanco@gmail.com",
+ "homepage": "http://www.instaclick.com"
+ },
+ {
+ "name": "Roman Borschel",
+ "email": "roman@code-factory.org"
+ },
+ {
+ "name": "Benjamin Eberlei",
+ "email": "kontakt@beberlei.de"
+ },
+ {
+ "name": "Johannes Schmitt",
+ "email": "schmittjoh@gmail.com",
+ "homepage": "https://github.com/schmittjoh",
+ "role": "Developer of wrapped JMSSerializerBundle"
+ }
+ ],
+ "description": "Caching library offering an object-oriented API for many cache backends",
+ "homepage": "http://www.doctrine-project.org",
+ "keywords": [
+ "cache",
+ "caching"
+ ]
+ },
+ {
"name": "doctrine/inflector",
"version": "v1.0",
"source": {
View
93 lib/Doctrine/Common/Cache/ApcCache.php
@@ -1,93 +0,0 @@
-<?php
-
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the MIT license. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\Common\Cache;
-
-/**
- * APC cache provider.
- *
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- * @link www.doctrine-project.org
- * @since 2.0
- * @author Benjamin Eberlei <kontakt@beberlei.de>
- * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
- * @author Jonathan Wage <jonwage@gmail.com>
- * @author Roman Borschel <roman@code-factory.org>
- * @author David Abdemoulaie <dave@hobodave.com>
- */
-class ApcCache extends CacheProvider
-{
- /**
- * {@inheritdoc}
- */
- protected function doFetch($id)
- {
- return apc_fetch($id);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doContains($id)
- {
- return apc_exists($id);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doSave($id, $data, $lifeTime = 0)
- {
- return (bool) apc_store($id, $data, (int) $lifeTime);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doDelete($id)
- {
- return apc_delete($id);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doFlush()
- {
- return apc_clear_cache() && apc_clear_cache('user');
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doGetStats()
- {
- $info = apc_cache_info();
- $sma = apc_sma_info();
-
- return array(
- Cache::STATS_HITS => $info['num_hits'],
- Cache::STATS_MISSES => $info['num_misses'],
- Cache::STATS_UPTIME => $info['start_time'],
- Cache::STATS_MEMORY_USAGE => $info['mem_size'],
- Cache::STATS_MEMORY_AVAILIABLE => $sma['avail_mem'],
- );
- }
-}
View
96 lib/Doctrine/Common/Cache/ArrayCache.php
@@ -1,96 +0,0 @@
-<?php
-/*
- * $Id$
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the MIT license. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\Common\Cache;
-
-/**
- * Array cache driver.
- *
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- * @link www.doctrine-project.org
- * @since 2.0
- * @author Benjamin Eberlei <kontakt@beberlei.de>
- * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
- * @author Jonathan Wage <jonwage@gmail.com>
- * @author Roman Borschel <roman@code-factory.org>
- * @author David Abdemoulaie <dave@hobodave.com>
- */
-class ArrayCache extends CacheProvider
-{
- /**
- * @var array $data
- */
- private $data = array();
-
- /**
- * {@inheritdoc}
- */
- protected function doFetch($id)
- {
- return (isset($this->data[$id])) ? $this->data[$id] : false;
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doContains($id)
- {
- return isset($this->data[$id]);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doSave($id, $data, $lifeTime = 0)
- {
- $this->data[$id] = $data;
-
- return true;
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doDelete($id)
- {
- unset($this->data[$id]);
-
- return true;
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doFlush()
- {
- $this->data = array();
-
- return true;
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doGetStats()
- {
- return null;
- }
-}
View
102 lib/Doctrine/Common/Cache/Cache.php
@@ -1,102 +0,0 @@
-<?php
-/*
- * $Id$
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the MIT license. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\Common\Cache;
-
-/**
- * Interface for cache drivers.
- *
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- * @link www.doctrine-project.org
- * @since 2.0
- * @author Benjamin Eberlei <kontakt@beberlei.de>
- * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
- * @author Jonathan Wage <jonwage@gmail.com>
- * @author Roman Borschel <roman@code-factory.org>
- * @author Fabio B. Silva <fabio.bat.silva@gmail.com>
- */
-interface Cache
-{
- const STATS_HITS = 'hits';
- const STATS_MISSES = 'misses';
- const STATS_UPTIME = 'uptime';
- const STATS_MEMORY_USAGE = 'memory_usage';
- const STATS_MEMORY_AVAILIABLE = 'memory_available';
-
- /**
- * Fetches an entry from the cache.
- *
- * @param string $id cache id The id of the cache entry to fetch.
- * @return mixed The cached data or FALSE, if no cache entry exists for the given id.
- */
- function fetch($id);
-
- /**
- * Test if an entry exists in the cache.
- *
- * @param string $id cache id The cache id of the entry to check for.
- * @return boolean TRUE if a cache entry exists for the given cache id, FALSE otherwise.
- */
- function contains($id);
-
- /**
- * Puts data into the cache.
- *
- * @param string $id The cache id.
- * @param mixed $data The cache entry/data.
- * @param int $lifeTime The lifetime. If != 0, sets a specific lifetime for this cache entry (0 => infinite lifeTime).
- * @return boolean TRUE if the entry was successfully stored in the cache, FALSE otherwise.
- */
- function save($id, $data, $lifeTime = 0);
-
- /**
- * Deletes a cache entry.
- *
- * @param string $id cache id
- * @return boolean TRUE if the cache entry was successfully deleted, FALSE otherwise.
- */
- function delete($id);
-
- /**
- * Retrieves cached information from data store
- *
- * The server's statistics array has the following values:
- *
- * - <b>hits</b>
- * Number of keys that have been requested and found present.
- *
- * - <b>misses</b>
- * Number of items that have been requested and not found.
- *
- * - <b>uptime</b>
- * Time that the server is running.
- *
- * - <b>memory_usage</b>
- * Memory used by this server to store items.
- *
- * - <b>memory_available</b>
- * Memory allowed to use for storage.
- *
- * @since 2.2
- * @return array Associative array with server's statistics if available, NULL otherwise.
- */
- function getStats();
-}
View
231 lib/Doctrine/Common/Cache/CacheProvider.php
@@ -1,231 +0,0 @@
-<?php
-
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the MIT license. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\Common\Cache;
-
-/**
- * Base class for cache provider implementations.
- *
- * @since 2.2
- * @author Benjamin Eberlei <kontakt@beberlei.de>
- * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
- * @author Jonathan Wage <jonwage@gmail.com>
- * @author Roman Borschel <roman@code-factory.org>
- * @author Fabio B. Silva <fabio.bat.silva@gmail.com>
- */
-abstract class CacheProvider implements Cache
-{
- const DOCTRINE_NAMESPACE_CACHEKEY = 'DoctrineNamespaceCacheKey[%s]';
-
- /**
- * @var string The namespace to prefix all cache ids with
- */
- private $namespace = '';
-
- /**
- * @var string The namespace version
- */
- private $namespaceVersion;
-
- /**
- * Set the namespace to prefix all cache ids with.
- *
- * @param string $namespace
- * @return void
- */
- public function setNamespace($namespace)
- {
- $this->namespace = (string) $namespace;
- }
-
- /**
- * Retrieve the namespace that prefixes all cache ids.
- *
- * @return string
- */
- public function getNamespace()
- {
- return $this->namespace;
- }
-
- /**
- * {@inheritdoc}
- */
- public function fetch($id)
- {
- return $this->doFetch($this->getNamespacedId($id));
- }
-
- /**
- * {@inheritdoc}
- */
- public function contains($id)
- {
- return $this->doContains($this->getNamespacedId($id));
- }
-
- /**
- * {@inheritdoc}
- */
- public function save($id, $data, $lifeTime = 0)
- {
- return $this->doSave($this->getNamespacedId($id), $data, $lifeTime);
- }
-
- /**
- * {@inheritdoc}
- */
- public function delete($id)
- {
- return $this->doDelete($this->getNamespacedId($id));
- }
-
- /**
- * {@inheritdoc}
- */
- public function getStats()
- {
- return $this->doGetStats();
- }
-
- /**
- * Deletes all cache entries.
- *
- * @return boolean TRUE if the cache entries were successfully flushed, FALSE otherwise.
- */
- public function flushAll()
- {
- return $this->doFlush();
- }
-
- /**
- * Delete all cache entries.
- *
- * @return boolean TRUE if the cache entries were successfully deleted, FALSE otherwise.
- */
- public function deleteAll()
- {
- $namespaceCacheKey = $this->getNamespaceCacheKey();
- $namespaceVersion = $this->getNamespaceVersion() + 1;
-
- $this->namespaceVersion = $namespaceVersion;
-
- return $this->doSave($namespaceCacheKey, $namespaceVersion);
- }
-
- /**
- * Prefix the passed id with the configured namespace value
- *
- * @param string $id The id to namespace
- * @return string $id The namespaced id
- */
- private function getNamespacedId($id)
- {
- $namespaceVersion = $this->getNamespaceVersion();
-
- return sprintf('%s[%s][%s]', $this->namespace, $id, $namespaceVersion);
- }
-
- /**
- * Namespace cache key
- *
- * @return string $namespaceCacheKey
- */
- private function getNamespaceCacheKey()
- {
- return sprintf(self::DOCTRINE_NAMESPACE_CACHEKEY, $this->namespace);
- }
-
- /**
- * Namespace version
- *
- * @return string $namespaceVersion
- */
- private function getNamespaceVersion()
- {
- if (null !== $this->namespaceVersion) {
- return $this->namespaceVersion;
- }
-
- $namespaceCacheKey = $this->getNamespaceCacheKey();
- $namespaceVersion = $this->doFetch($namespaceCacheKey);
-
- if (false === $namespaceVersion) {
- $namespaceVersion = 1;
-
- $this->doSave($namespaceCacheKey, $namespaceVersion);
- }
-
- $this->namespaceVersion = $namespaceVersion;
-
- return $this->namespaceVersion;
- }
-
- /**
- * Fetches an entry from the cache.
- *
- * @param string $id cache id The id of the cache entry to fetch.
- * @return string The cached data or FALSE, if no cache entry exists for the given id.
- */
- abstract protected function doFetch($id);
-
- /**
- * Test if an entry exists in the cache.
- *
- * @param string $id cache id The cache id of the entry to check for.
- * @return boolean TRUE if a cache entry exists for the given cache id, FALSE otherwise.
- */
- abstract protected function doContains($id);
-
- /**
- * Puts data into the cache.
- *
- * @param string $id The cache id.
- * @param string $data The cache entry/data.
- * @param bool|int $lifeTime The lifetime. If != false, sets a specific lifetime for this
- * cache entry (null => infinite lifeTime).
- *
- * @return boolean TRUE if the entry was successfully stored in the cache, FALSE otherwise.
- */
- abstract protected function doSave($id, $data, $lifeTime = false);
-
- /**
- * Deletes a cache entry.
- *
- * @param string $id cache id
- * @return boolean TRUE if the cache entry was successfully deleted, FALSE otherwise.
- */
- abstract protected function doDelete($id);
-
- /**
- * Deletes all cache entries.
- *
- * @return boolean TRUE if the cache entry was successfully deleted, FALSE otherwise.
- */
- abstract protected function doFlush();
-
- /**
- * Retrieves cached information from data store
- *
- * @since 2.2
- * @return array An associative array with server's statistics if available, NULL otherwise.
- */
- abstract protected function doGetStats();
-}
View
123 lib/Doctrine/Common/Cache/CouchbaseCache.php
@@ -1,123 +0,0 @@
-<?php
-
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the MIT license. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\Common\Cache;
-
-use \Couchbase;
-
-/**
- * Couchbase cache provider.
- *
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- * @link www.doctrine-project.org
- * @since 2.4
- * @author Michael Nitschinger <michael@nitschinger.at>
- */
-class CouchbaseCache extends CacheProvider
-{
-
- /**
- * @var Couchbase
- */
- private $couchbase;
-
- /**
- * Sets the Couchbase instance to use.
- *
- * @param Couchbase $couchbase
- */
- public function setCouchbase(Couchbase $couchbase)
- {
- $this->couchbase = $couchbase;
- }
-
- /**
- * Gets the Couchbase instance used by the cache.
- *
- * @return Couchbase
- */
- public function getCouchbase()
- {
- return $this->couchbase;
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doFetch($id)
- {
- return $this->couchbase->get($id) ?: false;
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doContains($id)
- {
- return (null !== $this->couchbase->get($id));
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doSave($id, $data, $lifeTime = 0)
- {
- if ($lifeTime > 30 * 24 * 3600) {
- $lifeTime = time() + $lifeTime;
- }
- return $this->couchbase->set($id, $data, (int) $lifeTime);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doDelete($id)
- {
- return $this->couchbase->delete($id);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doFlush()
- {
- return $this->couchbase->flush();
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doGetStats()
- {
- $stats = $this->couchbase->getStats();
- $servers = $this->couchbase->getServers();
- $server = explode(":", $servers[0]);
- $key = $server[0] . ":" . "11210";
- $stats = $stats[$key];
- return array(
- Cache::STATS_HITS => $stats['get_hits'],
- Cache::STATS_MISSES => $stats['get_misses'],
- Cache::STATS_UPTIME => $stats['uptime'],
- Cache::STATS_MEMORY_USAGE => $stats['bytes'],
- Cache::STATS_MEMORY_AVAILIABLE => $stats['limit_maxbytes'],
- );
- }
-
-}
View
132 lib/Doctrine/Common/Cache/FileCache.php
@@ -1,132 +0,0 @@
-<?php
-
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the MIT license. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\Common\Cache;
-
-/**
- * Base file cache driver.
- *
- * @since 2.3
- * @author Fabio B. Silva <fabio.bat.silva@gmail.com>
- */
-abstract class FileCache extends CacheProvider
-{
- /**
- * @var string Cache directory.
- */
- protected $directory;
-
- /**
- * @var string Cache file extension.
- */
- protected $extension;
-
- /**
- * Constructor
- *
- * @param string $directory Cache directory.
- * @param string $directory Cache file extension.
- *
- * @throws \InvalidArgumentException
- */
- public function __construct($directory, $extension = null)
- {
- if ( ! is_dir($directory) && ! @mkdir($directory, 0777, true)) {
- throw new \InvalidArgumentException(sprintf(
- 'The directory "%s" does not exist and could not be created.',
- $directory
- ));
- }
-
- if ( ! is_writable($directory)) {
- throw new \InvalidArgumentException(sprintf(
- 'The directory "%s" is not writable.',
- $directory
- ));
- }
-
- $this->directory = realpath($directory);
- $this->extension = $extension ?: $this->extension;
- }
-
- /**
- * Gets the cache directory.
- *
- * @return string
- */
- public function getDirectory()
- {
- return $this->directory;
- }
-
- /**
- * Gets the cache file extension.
- *
- * @return string
- */
- public function getExtension()
- {
- return $this->extension;
- }
-
- /**
- * @return string
- */
- protected function getFilename($id)
- {
- $path = implode(str_split(md5($id), 12), DIRECTORY_SEPARATOR);
- $path = $this->directory . DIRECTORY_SEPARATOR . $path;
-
- return $path . DIRECTORY_SEPARATOR . $id . $this->extension;
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doDelete($id)
- {
- return @unlink($this->getFilename($id));
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doFlush()
- {
- $pattern = '/^.+\\' . $this->extension . '$/i';
- $iterator = new \RecursiveDirectoryIterator($this->directory);
- $iterator = new \RecursiveIteratorIterator($iterator);
- $iterator = new \RegexIterator($iterator, $pattern);
-
- foreach ($iterator as $name => $file) {
- @unlink($name);
- }
-
- return true;
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doGetStats()
- {
- return null;
- }
-}
View
114 lib/Doctrine/Common/Cache/FilesystemCache.php
@@ -1,114 +0,0 @@
-<?php
-
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the MIT license. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\Common\Cache;
-
-/**
- * Filesystem cache driver.
- *
- * @since 2.3
- * @author Fabio B. Silva <fabio.bat.silva@gmail.com>
- */
-class FilesystemCache extends FileCache
-{
- const EXTENSION = '.doctrinecache.data';
-
- /**
- * {@inheritdoc}
- */
- protected $extension = self::EXTENSION;
-
- /**
- * {@inheritdoc}
- */
- protected function doFetch($id)
- {
- $data = '';
- $lifetime = -1;
- $filename = $this->getFilename($id);
-
- if ( ! is_file($filename)) {
- return false;
- }
-
- $resource = fopen($filename, "r");
-
- if (false !== ($line = fgets($resource))) {
- $lifetime = (integer) $line;
- }
-
- if ($lifetime !== 0 && $lifetime < time()) {
- fclose($resource);
-
- return false;
- }
-
- while (false !== ($line = fgets($resource))) {
- $data .= $line;
- }
-
- fclose($resource);
-
- return unserialize($data);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doContains($id)
- {
- $lifetime = -1;
- $filename = $this->getFilename($id);
-
- if ( ! is_file($filename)) {
- return false;
- }
-
- $resource = fopen($filename, "r");
-
- if (false !== ($line = fgets($resource))) {
- $lifetime = (integer) $line;
- }
-
- fclose($resource);
-
- return $lifetime === 0 || $lifetime > time();
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doSave($id, $data, $lifeTime = 0)
- {
- if ($lifeTime > 0) {
- $lifeTime = time() + $lifeTime;
- }
-
- $data = serialize($data);
- $filename = $this->getFilename($id);
- $filepath = pathinfo($filename, PATHINFO_DIRNAME);
-
- if ( ! is_dir($filepath)) {
- mkdir($filepath, 0777, true);
- }
-
- return file_put_contents($filename, $lifeTime . PHP_EOL . $data);
- }
-}
View
121 lib/Doctrine/Common/Cache/MemcacheCache.php
@@ -1,121 +0,0 @@
-<?php
-
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the MIT license. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\Common\Cache;
-
-use \Memcache;
-
-/**
- * Memcache cache provider.
- *
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- * @link www.doctrine-project.org
- * @since 2.0
- * @author Benjamin Eberlei <kontakt@beberlei.de>
- * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
- * @author Jonathan Wage <jonwage@gmail.com>
- * @author Roman Borschel <roman@code-factory.org>
- * @author David Abdemoulaie <dave@hobodave.com>
- */
-class MemcacheCache extends CacheProvider
-{
- /**
- * @var Memcache
- */
- private $memcache;
-
- /**
- * Sets the memcache instance to use.
- *
- * @param Memcache $memcache
- */
- public function setMemcache(Memcache $memcache)
- {
- $this->memcache = $memcache;
- }
-
- /**
- * Gets the memcache instance used by the cache.
- *
- * @return Memcache
- */
- public function getMemcache()
- {
- return $this->memcache;
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doFetch($id)
- {
- return $this->memcache->get($id);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doContains($id)
- {
- return (bool) $this->memcache->get($id);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doSave($id, $data, $lifeTime = 0)
- {
- if ($lifeTime > 30 * 24 * 3600) {
- $lifeTime = time() + $lifeTime;
- }
- return $this->memcache->set($id, $data, 0, (int) $lifeTime);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doDelete($id)
- {
- return $this->memcache->delete($id);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doFlush()
- {
- return $this->memcache->flush();
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doGetStats()
- {
- $stats = $this->memcache->getStats();
- return array(
- Cache::STATS_HITS => $stats['get_hits'],
- Cache::STATS_MISSES => $stats['get_misses'],
- Cache::STATS_UPTIME => $stats['uptime'],
- Cache::STATS_MEMORY_USAGE => $stats['bytes'],
- Cache::STATS_MEMORY_AVAILIABLE => $stats['limit_maxbytes'],
- );
- }
-}
View
124 lib/Doctrine/Common/Cache/MemcachedCache.php
@@ -1,124 +0,0 @@
-<?php
-
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the MIT license. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\Common\Cache;
-
-use \Memcached;
-
-/**
- * Memcached cache provider.
- *
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- * @link www.doctrine-project.org
- * @since 2.2
- * @author Benjamin Eberlei <kontakt@beberlei.de>
- * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
- * @author Jonathan Wage <jonwage@gmail.com>
- * @author Roman Borschel <roman@code-factory.org>
- * @author David Abdemoulaie <dave@hobodave.com>
- */
-class MemcachedCache extends CacheProvider
-{
- /**
- * @var Memcached
- */
- private $memcached;
-
- /**
- * Sets the memcache instance to use.
- *
- * @param Memcached $memcached
- */
- public function setMemcached(Memcached $memcached)
- {
- $this->memcached = $memcached;
- }
-
- /**
- * Gets the memcached instance used by the cache.
- *
- * @return Memcached
- */
- public function getMemcached()
- {
- return $this->memcached;
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doFetch($id)
- {
- return $this->memcached->get($id);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doContains($id)
- {
- return (false !== $this->memcached->get($id));
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doSave($id, $data, $lifeTime = 0)
- {
- if ($lifeTime > 30 * 24 * 3600) {
- $lifeTime = time() + $lifeTime;
- }
- return $this->memcached->set($id, $data, (int) $lifeTime);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doDelete($id)
- {
- return $this->memcached->delete($id);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doFlush()
- {
- return $this->memcached->flush();
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doGetStats()
- {
- $stats = $this->memcached->getStats();
- $servers = $this->memcached->getServerList();
- $key = $servers[0]['host'] . ':' . $servers[0]['port'];
- $stats = $stats[$key];
- return array(
- Cache::STATS_HITS => $stats['get_hits'],
- Cache::STATS_MISSES => $stats['get_misses'],
- Cache::STATS_UPTIME => $stats['uptime'],
- Cache::STATS_MEMORY_USAGE => $stats['bytes'],
- Cache::STATS_MEMORY_AVAILIABLE => $stats['limit_maxbytes'],
- );
- }
-}
View
108 lib/Doctrine/Common/Cache/PhpFileCache.php
@@ -1,108 +0,0 @@
-<?php
-
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the MIT license. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\Common\Cache;
-
-/**
- * Php file cache driver.
- *
- * @since 2.3
- * @author Fabio B. Silva <fabio.bat.silva@gmail.com>
- */
-class PhpFileCache extends FileCache
-{
- const EXTENSION = '.doctrinecache.php';
-
- /**
- * {@inheritdoc}
- */
- protected $extension = self::EXTENSION;
-
- /**
- * {@inheritdoc}
- */
- protected function doFetch($id)
- {
- $filename = $this->getFilename($id);
-
- if ( ! is_file($filename)) {
- return false;
- }
-
- $value = include $filename;
-
- if ($value['lifetime'] !== 0 && $value['lifetime'] < time()) {
- return false;
- }
-
- return $value['data'];
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doContains($id)
- {
- $filename = $this->getFilename($id);
-
- if ( ! is_file($filename)) {
- return false;
- }
-
- $value = include $filename;
-
- return $value['lifetime'] === 0 || $value['lifetime'] > time();
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doSave($id, $data, $lifeTime = 0)
- {
- if ($lifeTime > 0) {
- $lifeTime = time() + $lifeTime;
- }
-
- if (is_object($data) && ! method_exists($data, '__set_state')) {
- throw new \InvalidArgumentException(
- "Invalid argument given, PhpFileCache only allows objects that implement __set_state() " .
- "and fully support var_export(). You can use the FilesystemCache to save arbitrary object " .
- "graphs using serialize()/deserialize()."
- );
- }
-
- $filename = $this->getFilename($id);
- $filepath = pathinfo($filename, PATHINFO_DIRNAME);
-
- if ( ! is_dir($filepath)) {
- mkdir($filepath, 0777, true);
- }
-
- $value = array(
- 'lifetime' => $lifeTime,
- 'data' => $data
- );
-
- $value = var_export($value, true);
- $code = sprintf('<?php return %s;', $value);
-
- return file_put_contents($filename, $code);
- }
-}
View
119 lib/Doctrine/Common/Cache/RedisCache.php
@@ -1,119 +0,0 @@
-<?php
-
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the MIT license. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\Common\Cache;
-
-use Redis;
-
-/**
- * Redis cache provider.
- *
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- * @link www.doctrine-project.org
- * @since 2.2
- * @author Osman Ungur <osmanungur@gmail.com>
- */
-class RedisCache extends CacheProvider
-{
- /**
- * @var Redis
- */
- private $redis;
-
- /**
- * Sets the redis instance to use.
- *
- * @param Redis $redis
- */
- public function setRedis(Redis $redis)
- {
- $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_IGBINARY);
- $this->redis = $redis;
- }
-
- /**
- * Gets the redis instance used by the cache.
- *
- * @return Redis
- */
- public function getRedis()
- {
- return $this->redis;
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doFetch($id)
- {
- return $this->redis->get($id);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doContains($id)
- {
- return $this->redis->exists($id);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doSave($id, $data, $lifeTime = 0)
- {
- $result = $this->redis->set($id, $data);
- if ($lifeTime > 0) {
- $this->redis->expire($id, $lifeTime);
- }
- return $result;
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doDelete($id)
- {
- return $this->redis->delete($id);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doFlush()
- {
- return $this->redis->flushDB();
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doGetStats()
- {
- $info = $this->redis->info();
- return array(
- Cache::STATS_HITS => false,
- Cache::STATS_MISSES => false,
- Cache::STATS_UPTIME => $info['uptime_in_seconds'],
- Cache::STATS_MEMORY_USAGE => $info['used_memory'],
- Cache::STATS_MEMORY_AVAILIABLE => false
- );
- }
-}
View
93 lib/Doctrine/Common/Cache/WinCacheCache.php
@@ -1,93 +0,0 @@
-<?php
-
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the MIT license. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\Common\Cache;
-
-/**
- * WinCache cache provider.
- *
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- * @link www.doctrine-project.org
- * @since 2.2
- * @author Benjamin Eberlei <kontakt@beberlei.de>
- * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
- * @author Jonathan Wage <jonwage@gmail.com>
- * @author Roman Borschel <roman@code-factory.org>
- * @author David Abdemoulaie <dave@hobodave.com>
- */
-class WinCacheCache extends CacheProvider
-{
- /**
- * {@inheritdoc}
- */
- protected function doFetch($id)
- {
- return wincache_ucache_get($id);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doContains($id)
- {
- return wincache_ucache_exists($id);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doSave($id, $data, $lifeTime = 0)
- {
- return (bool) wincache_ucache_set($id, $data, (int) $lifeTime);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doDelete($id)
- {
- return wincache_ucache_delete($id);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doFlush()
- {
- return wincache_ucache_clear();
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doGetStats()
- {
- $info = wincache_ucache_info();
- $meminfo = wincache_ucache_meminfo();
-
- return array(
- Cache::STATS_HITS => $info['total_hit_count'],
- Cache::STATS_MISSES => $info['total_miss_count'],
- Cache::STATS_UPTIME => $info['total_cache_uptime'],
- Cache::STATS_MEMORY_USAGE => $meminfo['memory_total'],
- Cache::STATS_MEMORY_AVAILIABLE => $meminfo['memory_free'],
- );
- }
-}
View
110 lib/Doctrine/Common/Cache/XcacheCache.php
@@ -1,110 +0,0 @@
-<?php
-
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the MIT license. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\Common\Cache;
-
-/**
- * Xcache cache driver.
- *
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- * @link www.doctrine-project.org
- * @since 2.0
- * @author Benjamin Eberlei <kontakt@beberlei.de>
- * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
- * @author Jonathan Wage <jonwage@gmail.com>
- * @author Roman Borschel <roman@code-factory.org>
- * @author David Abdemoulaie <dave@hobodave.com>
- */
-class XcacheCache extends CacheProvider
-{
- /**
- * {@inheritdoc}
- */
- protected function doFetch($id)
- {
- return $this->doContains($id) ? unserialize(xcache_get($id)) : false;
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doContains($id)
- {
- return xcache_isset($id);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doSave($id, $data, $lifeTime = 0)
- {
- return xcache_set($id, serialize($data), (int) $lifeTime);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doDelete($id)
- {
- return xcache_unset($id);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doFlush()
- {
- $this->checkAuthorization();
-
- xcache_clear_cache(XC_TYPE_VAR, 0);
-
- return true;
- }
-
- /**
- * Checks that xcache.admin.enable_auth is Off
- *
- * @throws \BadMethodCallException When xcache.admin.enable_auth is On
- * @return void
- */
- protected function checkAuthorization()
- {
- if (ini_get('xcache.admin.enable_auth')) {
- throw new \BadMethodCallException('To use all features of \Doctrine\Common\Cache\XcacheCache, you must set "xcache.admin.enable_auth" to "Off" in your php.ini.');
- }
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doGetStats()
- {
- $this->checkAuthorization();
-
- $info = xcache_info(XC_TYPE_VAR, 0);
- return array(
- Cache::STATS_HITS => $info['hits'],
- Cache::STATS_MISSES => $info['misses'],
- Cache::STATS_UPTIME => null,
- Cache::STATS_MEMORY_USAGE => $info['size'],
- Cache::STATS_MEMORY_AVAILIABLE => $info['avail'],
- );
- }
-}
View
84 lib/Doctrine/Common/Cache/ZendDataCache.php
@@ -1,84 +0,0 @@
-<?php
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the MIT license. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\Common\Cache;
-
-/**
- * Zend Data Cache cache driver.
- *
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- * @link www.doctrine-project.org
- * @since 2.0
- * @author Ralph Schindler <ralph.schindler@zend.com>
- * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
- */
-class ZendDataCache extends CacheProvider
-{
- /**
- * {@inheritdoc}
- */
- protected function doFetch($id)
- {
- return zend_shm_cache_fetch($id);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doContains($id)
- {
- return (false !== zend_shm_cache_fetch($id));
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doSave($id, $data, $lifeTime = 0)
- {
- return zend_shm_cache_store($id, $data, $lifeTime);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doDelete($id)
- {
- return zend_shm_cache_delete($id);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doFlush()
- {
- $namespace = $this->getNamespace();
- if (empty($namespace)) {
- return zend_shm_cache_clear();
- }
- return zend_shm_cache_clear($namespace);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doGetStats()
- {
- return null;
- }
-}
View
20 tests/Doctrine/Tests/Common/Cache/ApcCacheTest.php
@@ -1,20 +0,0 @@
-<?php
-
-namespace Doctrine\Tests\Common\Cache;
-
-use Doctrine\Common\Cache\ApcCache;
-
-class ApcCacheTest extends CacheTest
-{
- public function setUp()
- {
- if ( ! extension_loaded('apc') || false === @apc_cache_info()) {
- $this->markTestSkipped('The ' . __CLASS__ .' requires the use of APC');
- }
- }
-
- protected function _getCacheDriver()
- {
- return new ApcCache();
- }
-}
View
21 tests/Doctrine/Tests/Common/Cache/ArrayCacheTest.php
@@ -1,21 +0,0 @@
-<?php
-
-namespace Doctrine\Tests\Common\Cache;
-
-use Doctrine\Common\Cache\ArrayCache;
-
-class ArrayCacheTest extends CacheTest
-{
- protected function _getCacheDriver()
- {
- return new ArrayCache();
- }
-
- public function testGetStats()
- {
- $cache = $this->_getCacheDriver();
- $stats = $cache->getStats();
-
- $this->assertNull($stats);
- }
-}
View
103 tests/Doctrine/Tests/Common/Cache/CacheTest.php
@@ -1,103 +0,0 @@
-<?php
-
-namespace Doctrine\Tests\Common\Cache;
-
-use Doctrine\Common\Cache\Cache;
-
-abstract class CacheTest extends \Doctrine\Tests\DoctrineTestCase
-{
- public function testBasics()
- {
- $cache = $this->_getCacheDriver();
-
- // Test save
- $cache->save('test_key', 'testing this out');
-
- // Test contains to test that save() worked
- $this->assertTrue($cache->contains('test_key'));
-
- // Test fetch
- $this->assertEquals('testing this out', $cache->fetch('test_key'));
-
- // Test delete
- $cache->save('test_key2', 'test2');
- $cache->delete('test_key2');
- $this->assertFalse($cache->contains('test_key2'));
- }
-
- public function testObjects()
- {
- $cache = $this->_getCacheDriver();
-
- // Fetch/save test with objects (Is cache driver serializes/unserializes objects correctly ?)
- $cache->save('test_object_key', new \ArrayObject());
- $this->assertTrue($cache->fetch('test_object_key') instanceof \ArrayObject);
- }
-
- public function testDeleteAll()
- {
- $cache = $this->_getCacheDriver();
- $cache->save('test_key1', '1');
- $cache->save('test_key2', '2');
- $cache->deleteAll();
-
- $this->assertFalse($cache->contains('test_key1'));
- $this->assertFalse($cache->contains('test_key2'));
- }
-
- public function testFlushAll()
- {
- $cache = $this->_getCacheDriver();
- $cache->save('test_key1', '1');
- $cache->save('test_key2', '2');
- $cache->flushAll();
-
- $this->assertFalse($cache->contains('test_key1'));
- $this->assertFalse($cache->contains('test_key2'));
- }
-
- public function testNamespace()
- {
- $cache = $this->_getCacheDriver();
- $cache->setNamespace('test_');
- $cache->save('key1', 'test');
-
- $this->assertTrue($cache->contains('key1'));
-
- $cache->setNamespace('test2_');
-
- $this->assertFalse($cache->contains('key1'));
- }
-
- /**
- * @group DCOM-43
- */
- public function testGetStats()
- {
- $cache = $this->_getCacheDriver();
- $stats = $cache->getStats();
-
- $this->assertArrayHasKey(Cache::STATS_HITS, $stats);
- $this->assertArrayHasKey(Cache::STATS_MISSES, $stats);
- $this->assertArrayHasKey(Cache::STATS_UPTIME, $stats);
- $this->assertArrayHasKey(Cache::STATS_MEMORY_USAGE, $stats);
- $this->assertArrayHasKey(Cache::STATS_MEMORY_AVAILIABLE, $stats);
- }
-
- /**
- * Make sure that all supported caches return "false" instead of "null" to be compatible
- * with ORM integration.
- */
- public function testFalseOnFailedFetch()
- {
- $cache = $this->_getCacheDriver();
- $result = $cache->fetch('nonexistent_key');
- $this->assertFalse($result);
- $this->assertNotNull($result);
- }
-
- /**
- * @return \Doctrine\Common\Cache\CacheProvider
- */
- abstract protected function _getCacheDriver();
-}
View
47 tests/Doctrine/Tests/Common/Cache/CouchbaseCacheTest.php
@@ -1,47 +0,0 @@
-<?php
-
-namespace Doctrine\Tests\Common\Cache;
-
-use Couchbase;
-use Doctrine\Common\Cache\CouchbaseCache;
-
-class CouchbaseCacheTest extends CacheTest
-{
- private $couchbase;
-
- public function setUp()
- {
- if (extension_loaded('couchbase')) {
- try {
- $this->couchbase = new Couchbase('127.0.0.1', 'Administrator', 'password', 'default');
- } catch(Exception $ex) {
- $this->markTestSkipped('Could not instantiate the Couchbase cache because of: ' . $ex);
- }
- } else {
- $this->markTestSkipped('The ' . __CLASS__ .' requires the use of the couchbase extension');
- }
- }
-
- public function testNoExpire()
- {
- $cache = $this->_getCacheDriver();
- $cache->save('noexpire', 'value', 0);
- sleep(1);
- $this->assertTrue($cache->contains('noexpire'), 'Couchbase provider should support no-expire');
- }
-
- public function testLongLifetime()
- {
- $cache = $this->_getCacheDriver();
- $cache->save('key', 'value', 30 * 24 * 3600 + 1);
-
- $this->assertTrue($cache->contains('key'), 'Couchbase provider should support TTL > 30 days');
- }
-
- protected function _getCacheDriver()
- {
- $driver = new CouchbaseCache();
- $driver->setCouchbase($this->couchbase);
- return $driver;
- }
-}
View
97 tests/Doctrine/Tests/Common/Cache/FilesystemCacheTest.php
@@ -1,97 +0,0 @@
-<?php
-
-namespace Doctrine\Tests\Common\Cache;
-
-use Doctrine\Common\Cache\FilesystemCache;
-
-/**
- * @group DCOM-101
- */
-class FilesystemCacheTest extends CacheTest
-{
- /**
- * @var \Doctrine\Common\Cache\FilesystemCache
- */
- private $driver;
-
- protected function _getCacheDriver()
- {
- $dir = sys_get_temp_dir() . "/doctrine_cache_". uniqid();
- $this->assertFalse(is_dir($dir));
-
- $this->driver = new FilesystemCache($dir);
- $this->assertTrue(is_dir($dir));
-
- return $this->driver;
- }
-
- public function testLifetime()
- {
- $cache = $this->_getCacheDriver();
-
- // Test save
- $cache->save('test_key', 'testing this out', 10);
-
- // Test contains to test that save() worked
- $this->assertTrue($cache->contains('test_key'));
-
- // Test fetch
- $this->assertEquals('testing this out', $cache->fetch('test_key'));
-
- // access private methods
- $getFilename = new \ReflectionMethod($cache, 'getFilename');
- $getNamespacedId = new \ReflectionMethod($cache, 'getNamespacedId');
-
- $getFilename->setAccessible(true);
- $getNamespacedId->setAccessible(true);
-
- $id = $getNamespacedId->invoke($cache, 'test_key');
- $filename = $getFilename->invoke($cache, $id);
-
- $data = '';
- $lifetime = 0;
- $resource = fopen($filename, "r");
-
- if (false !== ($line = fgets($resource))) {
- $lifetime = (integer) $line;
- }
-
- while (false !== ($line = fgets($resource))) {
- $data .= $line;
- }
-
- $this->assertNotEquals(0, $lifetime, "previous lifetime could not be loaded");
-
- // update lifetime
- $lifetime = $lifetime - 20;
- file_put_contents($filename, $lifetime . PHP_EOL . $data);
-
- // test expired data
- $this->assertFalse($cache->contains('test_key'));
- $this->assertFalse($cache->fetch('test_key'));
- }
-
- public function testGetStats()
- {
- $cache = $this->_getCacheDriver();
- $stats = $cache->getStats();
-
- $this->assertNull($stats);
- }
-
- public function tearDown()
- {
- $dir = $this->driver->getDirectory();
- $ext = $this->driver->getExtension();
- $iterator = new \RecursiveDirectoryIterator($dir);
-
- foreach (new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::CHILD_FIRST) as $file) {
- if ($file->isFile()) {
- @unlink($file->getRealPath());
- } else {
- @rmdir($file->getRealPath());
- }
- }
- }
-
-}
View
45 tests/Doctrine/Tests/Common/Cache/MemcacheCacheTest.php
@@ -1,45 +0,0 @@
-<?php
-
-namespace Doctrine\Tests\Common\Cache;
-
-use Doctrine\Common\Cache\MemcacheCache;
-
-class MemcacheCacheTest extends CacheTest
-{
- private $_memcache;
-
- public function setUp()
- {
- if (extension_loaded('memcache')) {
- $this->_memcache = new \Memcache;
- $ok = @$this->_memcache->connect('localhost', 11211);
- if (!$ok) {
- $this->markTestSkipped('The ' . __CLASS__ .' requires the use of memcache');
- }
- } else {
- $this->markTestSkipped('The ' . __CLASS__ .' requires the use of memcache');
- }
- }
-
- public function testNoExpire() {
- $cache = $this->_getCacheDriver();
- $cache->save('noexpire', 'value', 0);
- sleep(1);
- $this->assertTrue($cache->contains('noexpire'), 'Memcache provider should support no-expire');
- }
-
- public function testLongLifetime()
- {
- $cache = $this->_getCacheDriver();
- $cache->save('key', 'value', 30 * 24 * 3600 + 1);
- $this->assertTrue($cache->contains('key'), 'Memcache provider should support TTL > 30 days');
- }
-
- protected function _getCacheDriver()
- {
- $driver = new MemcacheCache();
- $driver->setMemcache($this->_memcache);
- return $driver;
- }
-
-}
View
48 tests/Doctrine/Tests/Common/Cache/MemcachedCacheTest.php
@@ -1,48 +0,0 @@
-<?php
-
-namespace Doctrine\Tests\Common\Cache;
-
-use Doctrine\Common\Cache\MemcachedCache;
-
-class MemcachedCacheTest extends CacheTest
-{
- private $memcached;
-
- public function setUp()
- {
- if (extension_loaded('memcached')) {
- $this->memcached = new \Memcached();
- $this->memcached->setOption(\Memcached::OPT_COMPRESSION, false);
- $this->memcached->addServer('127.0.0.1', 11211);
-
- $fh = @fsockopen('127.0.0.1', 11211);
- if (!$fh) {
- $this->markTestSkipped('The ' . __CLASS__ .' requires the use of memcache');
- }
- } else {
- $this->markTestSkipped('The ' . __CLASS__ .' requires the use of memcache');
- }
- }
-
- public function testNoExpire() {
- $cache = $this->_getCacheDriver();
- $cache->save('noexpire', 'value', 0);
- sleep(1);
- $this->assertTrue($cache->contains('noexpire'), 'Memcache provider should support no-expire');
- }
-
- public function testLongLifetime()
- {
- $cache = $this->_getCacheDriver();
- $cache->save('key', 'value', 30 * 24 * 3600 + 1);
-
- $this->assertTrue($cache->contains('key'), 'Memcached provider should support TTL > 30 days');
- }
-
- protected function _getCacheDriver()
- {
- $driver = new MemcachedCache();
- $driver->setMemcached($this->memcached);
- return $driver;
- }
-}
View
149 tests/Doctrine/Tests/Common/Cache/PhpFileCacheTest.php
@@ -1,149 +0,0 @@
-<?php
-
-namespace Doctrine\Tests\Common\Cache;
-
-use Doctrine\Common\Cache\PhpFileCache;
-
-/**
- * @group DCOM-101
- */
-class PhpFileCacheTest extends CacheTest
-{
- /**
- * @var \Doctrine\Common\Cache\PhpFileCache
- */
- private $driver;
-
- protected function _getCacheDriver()
- {
- $dir = sys_get_temp_dir() . "/doctrine_cache_". uniqid();
- $this->assertFalse(is_dir($dir));
-
- $this->driver = new PhpFileCache($dir);
- $this->assertTrue(is_dir($dir));
-
- return $this->driver;
- }
-
- public function testObjects()
- {
- $this->markTestSkipped('PhpFileCache does not support saving objects that dont implement __set_state()');
- }
-
- public function testLifetime()
- {
- $cache = $this->_getCacheDriver();
-
- // Test save
- $cache->save('test_key', 'testing this out', 10);
-
- // Test contains to test that save() worked
- $this->assertTrue($cache->contains('test_key'));
-
- // Test fetch
- $this->assertEquals('testing this out', $cache->fetch('test_key'));
-
- // access private methods
- $getFilename = new \ReflectionMethod($cache, 'getFilename');
- $getNamespacedId = new \ReflectionMethod($cache, 'getNamespacedId');
-
- $getFilename->setAccessible(true);
- $getNamespacedId->setAccessible(true);
-
- $id = $getNamespacedId->invoke($cache, 'test_key');
- $path = $getFilename->invoke($cache, $id);
- $value = include $path;
-
- // update lifetime
- $value['lifetime'] = $value['lifetime'] - 20;
- file_put_contents($path, '<?php return unserialize(' . var_export(serialize($value), true) . ');');
-
- // test expired data
- $this->assertFalse($cache->contains('test_key'));
- $this->assertFalse($cache->fetch('test_key'));
- }
-
- public function testImplementsSetState()