You are here

function authcache_enum_user_keys in Authenticated User Page Caching (Authcache) 7.2

Enumerate every possible authcache key for authenticated users.

Return an associative array where keys correspond to authcache keys and values represent the property record the key is derived from.

A nested structure containing information about key properties is returned by implementations of hook_authcache_enum_key_property_info:

$properties_info = array(
  'base_root' => array(
    'name' => 'The root URL of the host, excluding the path',
    'choices' => array(
      'http://www.example.com',
    ),
  ),
  'roles' => array(
    'name' => 'Account roles',
    'choices' => array(
      array(
        2,
      ),
      array(
        3,
      ),
      array(
        4,
      ),
      array(
        3,
        4,
      ),
    ),
  ),
);

It is necessary to convert this structure into a collection of sets of the following form:

$sets = array(
  'base_root' => array(
    'http://www.example.com',
  ),
  'roles' => array(
    array(
      2,
    ),
    array(
      3,
    ),
    array(
      4,
    ),
    array(
      3,
      4,
    ),
  ),
);

In order to generate a list of all permutations, the cartesian product operation is applied to the collection of sets. The result is a structure looking like this:

$cartesian_product = array(
  array(
    'base_root' => 'http://www.example.com',
    'roles' => array(
      2,
    ),
  ),
  array(
    'base_root' => 'http://www.example.com',
    'roles' => array(
      3,
    ),
  ),
  array(
    'base_root' => 'http://www.example.com',
    'roles' => array(
      4,
    ),
  ),
  array(
    'base_root' => 'http://www.example.com',
    'roles' => array(
      3,
      4,
    ),
  ),
);

For each entry an authcache key is computed.

1 call to authcache_enum_user_keys()
authcache_enum_keys in modules/authcache_enum/authcache_enum.module
Return a flat list of authcache keys and cache-keys used by anonymous users.

File

modules/authcache_enum/authcache_enum.module, line 81
Provides methods for computing and enumerating authcache keys

Code

function authcache_enum_user_keys() {
  $info =& drupal_static(__FUNCTION__);
  if (!isset($info)) {
    $properties_info = module_invoke_all('authcache_enum_key_property_info');

    // Invoke hook_authcache_enum_key_properties() for backwards compatibility.
    $properties_info += module_invoke_all('authcache_enum_key_properties');
    drupal_alter('authcache_enum_key_property_info', $properties_info);
    $sets = array();
    foreach ($properties_info as $key => $definition) {
      $sets[$key] = $definition['choices'];
    }
    $info = array();
    module_load_include('inc', 'authcache_enum', 'authcache_enum.comb');
    foreach (_authcache_enum_cartesian($sets) as $properties) {
      $authcache_key = authcache_user_key($properties);
      $info[$authcache_key] = $properties;
    }
    drupal_alter('authcache_enum_key_properties', $info);
  }
  return $info;
}