You are here

function ad_cache_file_adcacheapi in Advertisement 6.2

Same name and namespace in other branches
  1. 5.2 cache/file/ad_cache_file.module \ad_cache_file_adcacheapi()
  2. 5 cache/file/ad_cache_file.module \ad_cache_file_adcacheapi()
  3. 6.3 cache/file/ad_cache_file.module \ad_cache_file_adcacheapi()
  4. 6 cache/file/ad_cache_file.module \ad_cache_file_adcacheapi()
  5. 7 cache/file/ad_cache_file.module \ad_cache_file_adcacheapi()

Implementation of hook_adcacheapi().

File

cache/file/ad_cache_file.module, line 46
A plug in for the ad.module, providing a file cache mechanism for improved performance when displaying ads.

Code

function ad_cache_file_adcacheapi($op, $node = NULL) {
  if ($node == NULL) {
    $node = array();
  }
  switch ($op) {
    case 'display_variables':
      return array(
        'f' => variable_get('ad_files', 3),
        'p' => file_create_path(),
      );
    case 'method':
      return array(
        'file' => t('File'),
      );
    case 'description':
      return t('File based caching will usually offer better performance, however, some find it difficult to enable and it may not offer valid statistics if you are using multiple load balanced web servers.');
    case 'settings':
      $form = array();
      $form['file'] = array(
        '#type' => 'fieldset',
        '#title' => t('File cache settings'),
        '#collapsible' => TRUE,
        '#collapsed' => variable_get('ad_cache', 'none') == 'file' ? FALSE : TRUE,
      );
      $form['file']['ad_files'] = array(
        '#type' => 'select',
        '#title' => t('Number of cache files'),
        '#default_value' => variable_get('ad_files', 3),
        '#options' => drupal_map_assoc(array(
          1,
          3,
          5,
          10,
          15,
        )),
        '#description' => t('Please select the number of cache files the ad module should use.  Select a smaller value for better accuracy when performaing automatic actions on advertisements at specified thresholds.  Select a larger value for better performance.  This configuration option is only relevant if the file cache is enabled.'),
      );
      $period = drupal_map_assoc(array(
        15,
        30,
        60,
        600,
        1800,
        3600,
        21600,
        43200,
        86400,
      ), 'format_interval');
      $form['file']['ad_cache_file_lifetime'] = array(
        '#type' => 'select',
        '#title' => t('Cache lifetime'),
        '#default_value' => variable_get('ad_cache_file_lifetime', 60),
        '#options' => $period,
        '#description' => t('Specify how long information should be cached before ad statistics are updated in the database.  Increasing the cache lifetime can improve overall performance.  This configuration options is only relevant if the file cache is enabled.'),
      );
      $form['file']['ad_cache_file_rebuild'] = array(
        '#type' => 'submit',
        '#value' => t('Flush cached data'),
        '#submit' => array(
          'ad_cache_file_force_flush',
        ),
      );
      return $form;
    case 'settings_submit':
      variable_set('ad_cache_file_lifetime', $node['ad_cache_file_lifetime']);
      if ($node['ad_cache'] != 'file') {
        ad_cache_file_build(0, variable_get('ad_files', 3));
      }
      else {
        ad_cache_file_build($node['ad_files'], variable_get('ad_files', 3));
      }
      variable_set('ad_files', $node['ad_files']);
      break;
  }
}