本文整理汇总了PHP中CRM_Utils_Cache类的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_Cache类的具体用法?PHP CRM_Utils_Cache怎么用?PHP CRM_Utils_Cache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CRM_Utils_Cache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tearDown
public function tearDown()
{
global $civicrm_setting;
$civicrm_setting = $this->origSetting;
CRM_Utils_Cache::singleton()->flush();
parent::tearDown();
}
示例2: create
/**
* Create civicrm settings. This is the same as add but it clears the cache and
* reloads the config object
*
* @param array $params
* Associated array of civicrm variables.
*
* @return void
*/
public static function create($params)
{
self::add($params);
$cache = CRM_Utils_Cache::singleton();
$cache->delete('CRM_Core_Config');
$cache->delete('CRM_Core_Config' . CRM_Core_Config::domainID());
$config = CRM_Core_Config::singleton(TRUE, TRUE);
}
示例3: singleton
/**
* @param bool $fresh
* @return CRM_Cxn_CiviCxnHttp
*/
public static function singleton($fresh = FALSE)
{
if (self::$singleton === NULL || $fresh) {
$cache = CRM_Utils_Cache::create(array('name' => 'CiviCxnHttp', 'type' => Civi::settings()->get('debug_enabled') ? 'ArrayCache' : array('SqlGroup', 'ArrayCache'), 'prefetch' => FALSE));
self::$singleton = new CRM_Cxn_CiviCxnHttp($cache);
}
return self::$singleton;
}
示例4: setCache
static function setCache($values, $group, $componentID = NULL, $contactID = NULL)
{
if (!isset(self::$_cache)) {
self::$_cache = array();
}
$cacheKey = "CRM_Setting_{$group}_{$componentID}_{$contactID}";
self::$_cache[$cacheKey] = $values;
$globalCache = CRM_Utils_Cache::singleton();
$result = $globalCache->set($cacheKey, $values);
return $cacheKey;
}
示例5: CRM_Utils_Cache_Memcache
/**
* 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;
}
示例6: 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);
}
示例7: getPetitionActivityType
/**
* Find the activity type ID for petitions.
*
* @return int
* The activity type ID.
*/
public static function getPetitionActivityType()
{
$cache = CRM_Utils_Cache::singleton();
$petitionActivityType = $cache->get('petitionemail_petitionActivityType');
if (empty($petitionActivityType)) {
try {
$petitionTypeParams = array('name' => "activity_type", 'api.OptionValue.getsingle' => array('option_group_id' => '$value.id', 'name' => "Petition", 'options' => array('limit' => 1)), 'options' => array('limit' => 1));
$petitionTypeInfo = civicrm_api3('OptionGroup', 'getsingle', $petitionTypeParams);
} catch (CiviCRM_API3_Exception $e) {
$error = $e->getMessage();
CRM_Core_Error::debug_log_message(t('API Error: %1', array(1 => $error, 'domain' => 'com.aghstrategies.petitionemail')));
}
if (empty($petitionTypeInfo['api.OptionValue.getsingle']['value'])) {
return;
} else {
$petitionActivityType = $petitionTypeInfo['api.OptionValue.getsingle']['value'];
$cache->set('petitionemail_petitionActivityType', $petitionActivityType);
}
}
return $petitionActivityType;
}
示例8: 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;
}
示例9: populate
/**
* DEPRECATED generic populate method
* All pseudoconstant functions that use this method are also deprecated.
*
* The static array $var is populated from the db
* using the <b>$name DAO</b>.
*
* Note: any database errors will be trapped by the DAO.
*
* @param array $var the associative array we will fill
* @param string $name the name of the DAO
* @param boolean $all get all objects. default is to get only active ones.
* @param string $retrieve the field that we are interested in (normally name, differs in some objects)
* @param string $filter the field that we want to filter the result set with
* @param string $condition the condition that gets passed to the final query as the WHERE clause
*
* @return void
* @access public
* @static
*/
public static function populate(&$var, $name, $all = FALSE, $retrieve = 'name', $filter = 'is_active', $condition = NULL, $orderby = NULL, $key = 'id', $force = NULL)
{
$cacheKey = "CRM_PC_{$name}_{$all}_{$key}_{$retrieve}_{$filter}_{$condition}_{$orderby}";
$cache = CRM_Utils_Cache::singleton();
$var = $cache->get($cacheKey);
if ($var && empty($force)) {
return $var;
}
$object = new $name();
$object->selectAdd();
$object->selectAdd("{$key}, {$retrieve}");
if ($condition) {
$object->whereAdd($condition);
}
if (!$orderby) {
$object->orderBy($retrieve);
} else {
$object->orderBy($orderby);
}
if (!$all) {
$object->{$filter} = 1;
}
$object->find();
$var = array();
while ($object->fetch()) {
$var[$object->{$key}] = $object->{$retrieve};
}
$cache->set($cacheKey, $var);
}
示例10: getTableColumnGroup
/**
* Get the database table name and column name for a custom field.
*
* @param int $fieldID
* The fieldID of the custom field.
* @param bool $force
* Force the sql to be run again (primarily used for tests).
*
* @return array
* fatal is fieldID does not exists, else array of tableName, columnName
*/
public static function getTableColumnGroup($fieldID, $force = FALSE)
{
$cacheKey = "CRM_Core_DAO_CustomField_CustomGroup_TableColumn_{$fieldID}";
$cache = CRM_Utils_Cache::singleton();
$fieldValues = $cache->get($cacheKey);
if (empty($fieldValues) || $force) {
$query = "\nSELECT cg.table_name, cf.column_name, cg.id\nFROM civicrm_custom_group cg,\n civicrm_custom_field cf\nWHERE cf.custom_group_id = cg.id\nAND cf.id = %1";
$params = array(1 => array($fieldID, 'Integer'));
$dao = CRM_Core_DAO::executeQuery($query, $params);
if (!$dao->fetch()) {
CRM_Core_Error::fatal();
}
$dao->free();
$fieldValues = array($dao->table_name, $dao->column_name, $dao->id);
$cache->set($cacheKey, $fieldValues);
}
return $fieldValues;
}
示例11: getDefaultFromAddress
/**
* Find the site's default "from" address.
*
* @return string
* The default "from" name and address.
*/
public function getDefaultFromAddress()
{
if (empty($this->defaultFromAddress)) {
$cache = CRM_Utils_Cache::singleton();
$this->defaultFromAddress = $cache->get('petitionemail_defaultFromAddress');
}
if (empty($this->defaultFromAddress)) {
try {
$defaultMailParams = array('name' => "from_email_address", 'options' => array('limit' => 1), 'api.OptionValue.getsingle' => array('is_default' => 1, 'options' => array('limit' => 1)));
$defaultMail = civicrm_api3('OptionGroup', 'getsingle', $defaultMailParams);
if (empty($defaultMail['api.OptionValue.getsingle']['label']) || $defaultMail['api.OptionValue.getsingle']['label'] == $defaultMail['api.OptionValue.getsingle']['name']) {
// No site email.
// TODO: leave some kind of message with explanation.
return NULL;
}
$this->defaultFromAddress = $defaultMail['api.OptionValue.getsingle']['label'];
$cache->set('petitionemail_defaultFromAddress', $this->defaultFromAddress);
} catch (CiviCRM_API3_Exception $e) {
$error = $e->getMessage();
CRM_Core_Error::debug_log_message(t('API Error: %1', array(1 => $error, 'domain' => 'com.aghstrategies.petitionemail')));
}
}
return $this->defaultFromAddress;
}
示例12: populate
/**
* populate the object from the database. generic populate
* method
*
* The static array $var is populated from the db
* using the <b>$name DAO</b>.
*
* Note: any database errors will be trapped by the DAO.
*
* @param array $var the associative array we will fill
* @param string $name the name of the DAO
* @param boolean $all get all objects. default is to get only active ones.
* @param string $retrieve the field that we are interested in (normally name, differs in some objects)
* @param string $filter the field that we want to filter the result set with
* @param string $condition the condition that gets passed to the final query as the WHERE clause
*
* @return void
* @access public
* @static
*/
public static function populate(&$var, $name, $all = false, $retrieve = 'name', $filter = 'is_active', $condition = null, $orderby = null, $key = 'id')
{
$cacheKey = "CRM_PC_{$name}_{$all}_{$key}_{$retrieve}_{$filter}_{$condition}_{$orderby}";
$cache =& CRM_Utils_Cache::singleton();
$var = $cache->get($cacheKey);
if ($var) {
return $var;
}
require_once str_replace('_', DIRECTORY_SEPARATOR, $name) . ".php";
eval('$object = new ' . $name . '( );');
$object->selectAdd();
$object->selectAdd("{$key}, {$retrieve}");
if ($condition) {
$object->whereAdd($condition);
}
if (!$orderby) {
$object->orderBy($retrieve);
} else {
$object->orderBy($orderby);
}
if (!$all) {
$object->{$filter} = 1;
}
$object->find();
$var = array();
while ($object->fetch()) {
$var[$object->{$key}] = $object->{$retrieve};
}
$cache->set($cacheKey, $var);
}
示例13: group
/**
* @param $type
* @param null $contactID
* @param string $tableName
* @param null $allGroups
* @param null $includedGroups
*
* @return array
*/
public static function group($type, $contactID = NULL, $tableName = 'civicrm_saved_search', $allGroups = NULL, $includedGroups = NULL)
{
$acls = CRM_ACL_BAO_Cache::build($contactID);
$ids = array();
if (!empty($acls)) {
$aclKeys = array_keys($acls);
$aclKeys = implode(',', $aclKeys);
$cacheKey = "{$tableName}-{$aclKeys}";
$cache = CRM_Utils_Cache::singleton();
$ids = $cache->get($cacheKey);
if (!$ids) {
$query = "\nSELECT a.operation, a.object_id\n FROM civicrm_acl_cache c, civicrm_acl a\n WHERE c.acl_id = a.id\n AND a.is_active = 1\n AND a.object_table = %1\n AND a.id IN ( {$aclKeys} )\nGROUP BY a.operation,a.object_id\nORDER BY a.object_id\n";
$params = array(1 => array($tableName, 'String'));
$dao = CRM_Core_DAO::executeQuery($query, $params);
while ($dao->fetch()) {
if ($dao->object_id) {
if (self::matchType($type, $dao->operation)) {
$ids[] = $dao->object_id;
}
} else {
// this user has got the permission for all objects of this type
// check if the type matches
if (self::matchType($type, $dao->operation)) {
foreach ($allGroups as $id => $dontCare) {
$ids[] = $id;
}
}
break;
}
}
$cache->set($cacheKey, $ids);
}
}
if (empty($ids) && !empty($includedGroups) && is_array($includedGroups)) {
$ids = $includedGroups;
}
CRM_Utils_Hook::aclGroup($type, $contactID, $tableName, $allGroups, $ids);
return $ids;
}
示例14: getOptionValuesArray
/**
* Get the values of all option values given an option group ID. Store in system cache
* Does not take any filtering arguments. The object is to avoid hitting the DB and retrieve
* from memory
*
* @param int $optionGroupID
* The option group for which we want the values from.
*
* @return array
* an array of array of values for this option group
*/
public static function getOptionValuesArray($optionGroupID)
{
// check if we can get the field values from the system cache
$cacheKey = "CRM_Core_BAO_OptionValue_OptionGroupID_{$optionGroupID}";
$cache = CRM_Utils_Cache::singleton();
$optionValues = $cache->get($cacheKey);
if (empty($optionValues)) {
$dao = new CRM_Core_DAO_OptionValue();
$dao->option_group_id = $optionGroupID;
$dao->orderBy('weight ASC, label ASC');
$dao->find();
$optionValues = array();
while ($dao->fetch()) {
$optionValues[$dao->id] = array();
CRM_Core_DAO::storeValues($dao, $optionValues[$dao->id]);
}
$cache->set($cacheKey, $optionValues);
}
return $optionValues;
}
示例15: commonProcess
public function commonProcess(&$params)
{
require_once "CRM/Core/BAO/Setting.php";
CRM_Core_BAO_Setting::add($params);
// also delete the CRM_Core_Config key from the database
$cache =& CRM_Utils_Cache::singleton();
$cache->delete('CRM_Core_Config');
// save autocomplete search options
if (CRM_Utils_Array::value('autocompleteContactSearch', $params)) {
$config =& new CRM_Core_DAO_Preferences();
$config->domain_id = CRM_Core_Config::domainID();
$config->find(true);
$config->contact_autocomplete_options = CRM_Core_BAO_CustomOption::VALUE_SEPERATOR . implode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, array_keys($params['autocompleteContactSearch'])) . CRM_Core_BAO_CustomOption::VALUE_SEPERATOR;
$config->save();
}
CRM_Core_Session::setStatus(ts('Your changes have been saved.'));
}