partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 145c1628f8fd4a9551ca2b66ff903d3417c28b99
parent bcc41566ab642d965db4841813b287e586b80c2c
Author: Felicitus <felicitus@felicitus.org>
Date:   Tue, 10 Jul 2012 23:21:50 +0200

Added more cache implementations for PartKeepr

Diffstat:
Mconfig.php.template | 25+++++++++++++++++++++++--
Msrc/backend/PartKeepr/PartKeepr.php | 39+++++++++++++++++++++++++++++++++++----
2 files changed, 58 insertions(+), 6 deletions(-)

diff --git a/config.php.template b/config.php.template @@ -160,4 +160,26 @@ Configuration::setOption("partkeepr.logger.enable", false); * * You need to make sure that the path to the file exists and that the file is writable. */ -Configuration::setOption("partkeepr.logger.outputfile", "/tmp/partkeepr.log");- \ No newline at end of file +Configuration::setOption("partkeepr.logger.outputfile", "/tmp/partkeepr.log"); + +/** + * Specifies the cache implementation. You can choose from one of these: + * + * - none + * - APC + * - MemCache + * - XCache + * + * Please note that you need additional options for memcache. + */ +Configuration::setOption("partkeepr.cache.implementation", "APC"); + +/** + * Specifies the memcache hostname. Defaults to localhost + */ +Configuration::setOption("partkeepr.cache.memcache.host", "localhost"); + +/** + * Specifies the memcache port. Defaults to 11211 + */ +Configuration::setOption("partkeepr.cache.memcache.port", "11211"); diff --git a/src/backend/PartKeepr/PartKeepr.php b/src/backend/PartKeepr/PartKeepr.php @@ -166,12 +166,43 @@ class PartKeepr { $connectionOptions = PartKeepr::createConnectionOptionsFromConfig(); - if (extension_loaded("apc")) { - $cache = new \Doctrine\Common\Cache\ApcCache(); - } else { - $cache = new \Doctrine\Common\Cache\ArrayCache(); + switch (strtolower(PartKeeprConfiguration::getOption("partkeepr.cache.implementation", "default"))) { + case "apc": + $cache = new \Doctrine\Common\Cache\ApcCache(); + break; + case "xcache": + if (php_sapi_name() !== "cli") { + $cache = new \Doctrine\Common\Cache\XcacheCache(); + } else { + // For CLI SAPIs, revert to the ArrayCache as Xcache spits out strange warnings when running in CLI. + $cache = new \Doctrine\Common\Cache\ArrayCache(); + } + + break; + case "memcache": + $memcache = new \Memcache(); + $memcache->connect( PartKeeprConfiguration::getOption("partkeepr.cache.memcache.host", "localhost"), + PartKeeprConfiguration::getOption("partkeepr.cache.memcache.port", "11211")); + $cache = new \Doctrine\Common\Cache\MemcacheCache(); + $cache->setMemcache($memcache); + break; + case "default": + case "auto": + if (extension_loaded("xcache")) { + $cache = new \Doctrine\Common\Cache\XcacheCache(); + } else if (extension_loaded("apc")) { + $cache = new \Doctrine\Common\Cache\ApcCache(); + } else { + $cache = new \Doctrine\Common\Cache\ArrayCache(); + } + break; + case "none": + $cache = new \Doctrine\Common\Cache\ArrayCache(); + break; } + echo get_class($cache); + $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache);