function rules_get_cache

Gets a rules cache entry.

36 calls to rules_get_cache()
RulesData::typesMatch in includes/rules.state.inc
Returns whether the type match. They match if type1 is compatible to type2.
RulesDataInputEvaluator::getEvaluatorOptions in includes/rules.processor.inc
Generates the evaluator $options.
RulesDataUI::selectionForm in ui/ui.data.inc
Provides the selection form for a parameter.
RulesExtendable::setUp in includes/rules.core.inc
RulesIntegrationTestCase::testAccessCallbacks in tests/rules.test
Just makes sure the access callback run without errors.

... See full list

3 string references to 'rules_get_cache'
RulesPlugin::save in includes/rules.core.inc
Saves the configuration to the database.
rules_clear_cache in ./rules.module
Clears the rule set cache.
rules_set_cache in ./rules.module
Sets a rules cache item.

File

./rules.module, line 398

Code

function &rules_get_cache($cid = 'data') {
    // Make use of the fast, advanced drupal static pattern.
    static $drupal_static_fast;
    if (!isset($drupal_static_fast)) {
        $drupal_static_fast['cache'] =& drupal_static(__FUNCTION__, array());
    }
    $cache =& $drupal_static_fast['cache'];
    if (!isset($cache[$cid])) {
        // The main 'data' cache includes translated strings, so each language is
        // cached separately.
        $cid_suffix = $cid == 'data' ? ':' . $GLOBALS['language']->language : '';
        if ($get = cache_get($cid . $cid_suffix, 'cache_rules')) {
            $cache[$cid] = $get->data;
        }
        else {
            // Prevent stampeding by ensuring the cache is rebuilt just once at the
            // same time.
            while (!lock_acquire(__FUNCTION__ . $cid . $cid_suffix, 60)) {
                // Now wait until the lock is released.
                lock_wait(__FUNCTION__ . $cid . $cid_suffix, 30);
                // If the lock is released it's likely the cache was rebuild. Thus check
                // again if we can fetch it from the persistent cache.
                if ($get = cache_get($cid . $cid_suffix, 'cache_rules')) {
                    $cache[$cid] = $get->data;
                    return $cache[$cid];
                }
            }
            if ($cid === 'data') {
                // There is no 'data' cache so we need to rebuild it. Make sure
                // subsequent cache gets of the main 'data' cache during rebuild get
                // the interim cache by passing in the reference of the static cache
                // variable.
                _rules_rebuild_cache($cache['data']);
            }
            elseif (strpos($cid, 'comp_') === 0) {
                $cache[$cid] = FALSE;
                _rules_rebuild_component_cache();
            }
            elseif (strpos($cid, 'event_') === 0 || $cid == 'rules_event_whitelist') {
                $cache[$cid] = FALSE;
                RulesEventSet::rebuildEventCache();
            }
            else {
                $cache[$cid] = FALSE;
            }
            // Ensure a set lock is released.
            lock_release(__FUNCTION__ . $cid . $cid_suffix);
        }
    }
    return $cache[$cid];
}