Ejemplo n.º 1
0
#!/usr/bin/php
<?php 
// Ya ... not really a unit test, but hey its a test ;)
ini_set('display_errors', true);
require_once 'memcache.class.php';
cacheMemcache::connect(array(array('localhost' => 11211)));
// normally this is done in the configs
print "Starting test!\n";
for ($i = 0; $i < 100; $i++) {
    $key = 'testkey-' . $i;
    cacheMemcache::set($key, $i, 400);
    $result = cacheMemcache::get($key);
    if ($result === false) {
        print 'Got false: ' . $key;
    } else {
        if ($result != $i) {
            print 'Got different result: ' . $key . ' => ' . $result;
        } else {
            print "Ok: {$result}\n";
        }
    }
}
print "Ending test!\n";
Ejemplo n.º 2
0
 /**
  * grab from cache
  *
  * @param 	string	$url		key for our cache
  * @return 	string	$short_url	data from cache
  */
 protected function cacheGetUrl($url)
 {
     if (!class_exists('Memcache')) {
         return false;
     }
     require_once dirname(__FILE__) . '/memcache.class.php';
     if (!cacheMemcache::connect(array(array('localhost' => 11211)))) {
         return false;
     }
     // normally this is done in the configs
     $cache_name = $this->class . '-' . md5($url);
     $this->debug(sprintf('GETTING: %s WITH CACHE KEY: %s', $url, $cache_name));
     return @cacheMemcache::get($cache_name);
 }
Ejemplo n.º 3
0
 /**
  * Sets self::$thin_mode.	If self::$thin_mode is true, calls to
  * get() will not check or store results in a local instance
  * variable.	This is primarily for use with long-running cron
  * jobs that instantiate many objects and would otherwise max out memory.
  */
 public static function setThinMode($mode = true)
 {
     self::$thin_mode = $mode === true || $mode === false ? $mode : false;
     // uhhh ... is_bool()?
 }