Newer
Older
catch
committed
<?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,
);
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'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,
);
catch
committed
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();
}