Example #1
0
 /**
  * キャッシュを初期化する。
  *
  * @param string $server
  * @param string $file
  * @param int $expires
  */
 public function init($server, $file, $expires)
 {
     parent::init($server, $file, $expires);
     if (Vizualizer_Configure::get("cache")) {
         $filename = $this->cacheRoot . DIRECTORY_SEPARATOR . $this->server . DIRECTORY_SEPARATOR . $this->file . ".php";
         if (file_exists($filename) && time() < fileatime($filename) + $this->expires) {
             require_once $filename;
         }
     } else {
         $this->values = array();
     }
 }
Example #2
0
 public function getAddressData($address)
 {
     $key = $this->language . ":" . $address;
     $location = $this->cache->get($key);
     if (empty($location)) {
         // ベースURLを取得
         $baseUrl = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=";
         // 追加ヘッダ情報を設定
         $options = array("http" => array("header" => "Accept-Language: " . $this->language));
         $context = stream_context_create($options);
         // コンテンツを取得
         if (preg_match("/^([^0-9]+)([0-9]+)?([^0-9]*[0-9]+)?([^0-9]*[0-9]+)?/", mb_convert_kana($address, "n"), $p) > 0) {
             $address = $p[0];
         }
         $location = file_get_contents($baseUrl . urlencode($address), false, $context);
         $this->cache->set($key, $location);
     }
     $data = json_decode($location);
     if ($data->status == "OK") {
         return $data->results;
     } else {
         return array();
     }
 }
Example #3
0
 /**
  * キャッシュの初期化を行う。
  *
  * @param string $server
  * @param string $file
  * @param int $expires
  */
 public function init($server, $file, $expires = 3600)
 {
     parent::init($server, $file, $expires);
     if (Vizualizer_Configure::get("cache")) {
         $this->mem = new Memcache();
         if (strpos(Vizualizer_Configure::get("memcache"), ":") > 0) {
             list($host, $port) = explode(":", Vizualizer_Configure::get("memcache"));
         } else {
             $host = Vizualizer_Configure::get("memcache");
             $port = 0;
         }
         if (!($port > 0)) {
             $port = 11211;
         }
         $this->mem->connect($host, $port);
         $this->values = unserialize($this->mem->get($server . ":" . $file));
     } else {
         $this->values = array();
     }
 }