Doctrine\Common\Cache\CacheProvider::save PHP Метод

save() публичный Метод

public save ( $id, $data, $lifeTime )
    public function save($id, $data, $lifeTime = 0)
    {
        return $this->doSave($this->getNamespacedId($id), $data, $lifeTime);
    }

Usage Example

Пример #1
0
 /**
  * TCMB sitesi üzerinden XML'i okur.
  *
  * @param Curl $curl
  *
  * @throws Exception\ConnectionFailed
  */
 private function getTcmbData(Curl $curl = null)
 {
     if (is_null($curl)) {
         $curl = new Curl();
     }
     $curl->setOption(CURLOPT_URL, 'http://www.tcmb.gov.tr/kurlar/today.xml');
     $curl->setOption(CURLOPT_HEADER, 0);
     $curl->setOption(CURLOPT_RETURNTRANSFER, 1);
     $curl->setOption(CURLOPT_FOLLOWLOCATION, 1);
     $response = $curl->exec();
     if ($response === false) {
         throw new Exception\ConnectionFailed('Sunucu Bağlantısı Kurulamadı: ' . $curl->error());
     }
     $curl->close();
     $this->data = $this->formatTcmbData((array) simplexml_load_string($response));
     $timezone = new \DateTimeZone('Europe/Istanbul');
     $now = new \DateTime('now', $timezone);
     $expire = $this->data['today'] == $now->format('d.m.Y') ? 'Tomorrow 15:30' : 'Today 15:30';
     $expireDate = new \DateTime($expire, $timezone);
     $this->data['expire'] = $expireDate->getTimestamp();
     if (!is_null($this->cacheDriver)) {
         $lifetime = $expire - $now->getTimestamp();
         // Eğer dosyanın geçerlilik süresi bitmişse veriyi sadece 5 dakika önbellekte tutuyoruz.
         $this->cacheDriver->save($this->cacheKey, $this->data, $lifetime > 0 ? $lifetime : 300);
     }
 }
All Usage Examples Of Doctrine\Common\Cache\CacheProvider::save