本文整理匯總了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;
}