本文整理汇总了PHP中CRM_Utils_Cache::_singleton方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_Cache::_singleton方法的具体用法?PHP CRM_Utils_Cache::_singleton怎么用?PHP CRM_Utils_Cache::_singleton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Utils_Cache
的用法示例。
在下文中一共展示了CRM_Utils_Cache::_singleton方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
/**
* singleton function used to manage this object
*
* @param string $host the memcached server host
* @param int $port the memcached server port
* @param int $timeout the default timeout
*
* @return object
* @static
*
*/
static function &singleton($host = 'localhost', $port = 11211, $timeout = 3600)
{
if (self::$_singleton === null) {
if (defined('CIVICRM_USE_MEMCACHE') && CIVICRM_USE_MEMCACHE) {
require_once 'CRM/Utils/Cache/Memcache.php';
self::$_singleton = new CRM_Utils_Cache_Memcache($host, $port, $timeout);
} else {
self::$_singleton = new CRM_Utils_Cache();
}
}
return self::$_singleton;
}
示例2: testSetGetItem
public function testSetGetItem()
{
$originalValue = array('abc' => 'def');
CRM_Core_BAO_Cache::setItem($originalValue, __CLASS__, 'testSetGetItem');
$return_1 = CRM_Core_BAO_Cache::getItem(__CLASS__, 'testSetGetItem');
$this->assertEquals($originalValue, $return_1);
// Wipe out any in-memory copies of the cache. Check to see if the SQL
// read is correct.
CRM_Core_BAO_Cache::$_cache = NULL;
CRM_Utils_Cache::$_singleton = NULL;
$return_2 = CRM_Core_BAO_Cache::getItem(__CLASS__, 'testSetGetItem');
$this->assertEquals($originalValue, $return_2);
}
示例3: elseif
/**
* Singleton function used to manage this object.
*
* @return CRM_Utils_Cache_Interface
*/
public static function &singleton()
{
if (self::$_singleton === NULL) {
$className = 'ArrayCache';
// default to ArrayCache for now
// Maintain backward compatibility for now.
// Setting CIVICRM_USE_MEMCACHE or CIVICRM_USE_ARRAYCACHE will
// override the CIVICRM_DB_CACHE_CLASS setting.
// Going forward, CIVICRM_USE_xxxCACHE should be deprecated.
if (defined('CIVICRM_USE_MEMCACHE') && CIVICRM_USE_MEMCACHE) {
$className = 'Memcache';
} elseif (defined('CIVICRM_USE_ARRAYCACHE') && CIVICRM_USE_ARRAYCACHE) {
$className = 'ArrayCache';
} elseif (defined('CIVICRM_DB_CACHE_CLASS') && CIVICRM_DB_CACHE_CLASS) {
$className = CIVICRM_DB_CACHE_CLASS;
}
// a generic method for utilizing any of the available db caches.
$dbCacheClass = 'CRM_Utils_Cache_' . $className;
$settings = self::getCacheSettings($className);
self::$_singleton = new $dbCacheClass($settings);
}
return self::$_singleton;
}