Beispiel #1
0
 /**
  * set it and forget it
  *
  * @param	string	$url		the url we use for the key
  * @param	string	$data		the short url to store
  * @param	int		$expiry		time in seconds to cache the entry
  * @return	boolean			true on success false on fail
  */
 protected function cacheSetUrl($url, $data, $expiry = null)
 {
     if (!class_exists('Memcache')) {
         return false;
     }
     if (!$expiry) {
         $expiry = $this->cache_time;
     }
     require_once dirname(__FILE__) . '/memcache.class.php';
     $cache_name = $this->class . '-' . md5($url);
     $this->debug(sprintf('ADDING: %s TO CACHE WITH KEY: %s AND EXPIRES %s', $data, $cache_name, $expiry));
     return cacheMemcache::set($cache_name, $data, false, $expiry);
 }
Beispiel #2
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";