You are here

memcache_test.module in Memcache API and Integration 7

Same filename and directory in other branches
  1. 6 tests/memcache_test.module

File

tests/memcache_test.module
View source
<?php

/**
 * Implements hook_menu().
 */
function memcache_test_menu() {
  $items['memcache-test/lock-acquire'] = array(
    'title' => 'Lock acquire',
    'page callback' => 'memcache_test_lock_acquire',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
  $items['memcache-test/lock-exit'] = array(
    'title' => 'Lock acquire then exit',
    'page callback' => 'memcache_test_lock_exit',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
  $items['memcache-test/set/%'] = array(
    'title' => 'Set a value with a key',
    'page callback' => 'memcache_test_set',
    'page arguments' => array(
      2,
      3,
    ),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
  $items['memcache-test/get/%'] = array(
    'title' => 'Get a value from the cache',
    'page callback' => 'memcache_test_get',
    'page arguments' => array(
      2,
    ),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
  $items['memcache-test/wildcard-clear/%'] = array(
    'title' => 'Clear the cache with a wildcard',
    'page callback' => 'memcache_test_wildcard_flush',
    'page arguments' => array(
      2,
    ),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
  $items['memcache-test/clear/%'] = array(
    'title' => 'Clear the cache with a wildcard',
    'page callback' => 'memcache_test_clear',
    'page arguments' => array(
      2,
    ),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
  $items['memcache-test/clear-cache'] = array(
    'title' => 'Clear the cache with a wildcard',
    'page callback' => 'memcache_test_clear_cache',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
  return $items;
}

/**
 * Try to acquire a named lock and report the outcome.
 */
function memcache_test_lock_acquire() {
  if (lock_acquire('memcache_test_lock_acquire')) {
    lock_release('memcache_test_lock_acquire');
    return 'TRUE: Lock successfully acquired in memcache_test_lock_acquire()';
  }
  else {
    return 'FALSE: Lock not acquired in memcache_test_lock_acquire()';
  }
}

/**
 * Try to acquire a specific lock, and then exit.
 */
function memcache_test_lock_exit() {
  if (lock_acquire('memcache_test_lock_exit', 900)) {
    echo 'TRUE: Lock successfully acquired in memcache_test_lock_exit()';

    // The shut-down function should release the lock.
    exit;
  }
  else {
    return 'FALSE: Lock not acquired in memcache_test_lock_exit()';
  }
}

/**
 * Set a value into the cache.
 */
function memcache_test_set($key, $value) {
  $cache = cache_set($key, $value, 'MemcacheDrupal');
  drupal_json_output(cache_get($key, 'MemcacheDrupal'));
}

/**
 * Set a value into the cache.
 */
function memcache_test_get($key) {
  $GLOBALS['in_test'] = TRUE;
  drupal_json_output(cache_get($key, 'MemcacheDrupal'));
}

/**
 * Clear cache using a wildcard.
 */
function memcache_test_wildcard_flush($key) {
  $_SESSION['cache_flush'] = array();
  cache_clear_all($key, 'MemcacheDrupal', TRUE);
  drupal_json_output($key);
}

/**
 * Clear cache using a specific key.
 */
function memcache_test_clear($key) {
  cache_clear_all($key, 'MemcacheDrupal');
  drupal_json_output($key);
}

/**
* Clear complete cache.
*/
function memcache_test_clear_cache() {
  cache_clear_all(NULL, 'MemcacheDrupal');
  drupal_json_output();
}

Functions

Namesort descending Description
memcache_test_clear Clear cache using a specific key.
memcache_test_clear_cache Clear complete cache.
memcache_test_get Set a value into the cache.
memcache_test_lock_acquire Try to acquire a named lock and report the outcome.
memcache_test_lock_exit Try to acquire a specific lock, and then exit.
memcache_test_menu Implements hook_menu().
memcache_test_set Set a value into the cache.
memcache_test_wildcard_flush Clear cache using a wildcard.