Exemplo n.º 1
0
 public function __init()
 {
     $this->user = logged_in() ? Visitor::current()->login : "******";
     $this->path = INCLUDES_DIR . "/caches/" . sanitize($this->user);
     $this->caches = INCLUDES_DIR . "/caches";
     $this->url = self_url();
     $this->file = $this->path . "/" . md5($this->url) . ".html";
     # If the cache directory is not writable, disable this module and cancel execution.
     if (!is_writable($this->caches)) {
         cancel_module("cacher");
     }
     # Prepare actions that should result in new cache files.
     $this->prepare_cache_updaters();
     # Remove all expired files.
     $this->remove_expired();
     $config = Config::current();
     $config->cache_exclude = (array) $config->cache_exclude;
     if (!empty($config->cache_exclude)) {
         foreach ($config->cache_exclude as &$exclude) {
             if (substr($exclude, 7) != "http://") {
                 $exclude = $config->url . "/" . ltrim($exclude, "/");
             }
         }
     }
 }
Exemplo n.º 2
0
 public function __construct($url, $config)
 {
     $this->user = logged_in() ? Visitor::current()->login : "******";
     $this->path = INCLUDES_DIR . "/caches/" . sanitize($this->user);
     $this->caches = INCLUDES_DIR . "/caches";
     $this->url = $url;
     $this->file = $this->path . "/" . md5($this->url) . ".html";
     # If the cache directory is not writable, disable this module and cancel execution.
     if (!is_writable($this->caches)) {
         cancel_module("cacher");
     }
     # Remove all expired files.
     $this->remove_expired();
 }
Exemplo n.º 3
0
 public function __construct($url, $config)
 {
     $raw_hosts = (array) $config->cache_memcached_hosts;
     $this->user = logged_in() ? Visitor::current()->login : "******";
     $this->memcache = new Memcache();
     $this->url = $url;
     $this->config = $config;
     $disable_module = true;
     foreach ($raw_hosts as $raw) {
         $raw = trim($raw);
         if ($raw == '') {
             continue;
         }
         $stack = explode(':', $raw);
         $host = false;
         $port = 11211;
         if (count($stack) == 9 or count($stack) == 2) {
             # ipv6 with port is 9, ipv4 with port is 2
             $port = array_pop($stack);
         }
         if (count($stack) == 1) {
             $host = $stack[0];
         }
         if (count($stack) == 8) {
             # ipv6 is 8 entries
             $host = implode(':', $stack);
         }
         if ($host === false and count($stack) > 0) {
             # probably a uri for other transit
             $host = implode(':', $stack);
             $port = 0;
             # other transit requires a port of 0
         }
         if ($host === false) {
             error_log("Memcached error: {$raw} is an invalid host address");
         } else {
             $this->memcache->addServer($host, $port);
             $disable_module = false;
         }
     }
     //$disable_module = true;
     if ($disable_module) {
         cancel_module("cacher");
     }
 }