/** * @param string $key * @return mixed * @throws KeyNotFoundException */ public function load($key) { if ($this->memoryCache->hasKey($key)) { return $this->memoryCache->load($key); } else { if ($this->fileCache->hasKey($key)) { return $this->fileCache->load($key); } } throw new KeyNotFoundException(); }
/** * Method, which control caching data before connect to MHD server */ private function cacher() { if (is_null($this->cache)) { if (class_exists('Memcache') && $this->cacheType !== 'filecache') { $this->cache = new MemoryCache(); } else { $this->cache = new FileCache(dirname(__FILE__) . '/../cache/' . md5($this->link) . '.tmp'); } } if ($this->cacheType == 'filecache') { $this->cache = new FileCache(dirname(__FILE__) . '/../cache/' . md5($this->link) . '.tmp'); } $this->cache->load(); $cache_expire = $this->expire_time; //seconds if (!isset($this->cache->last_update) || !isset($this->cache->last_update['spoje']) || $this->cache->last_update['spoje'] + $cache_expire < time()) { unset($this->cache->spoje); } if (!isset($this->cache->last_update) || !isset($this->cache->last_update['form_url']) || $this->cache->last_update['form_url'] + $cache_expire < time()) { unset($this->cache->form_url); } if (isset($this->cache->last_update) && isset($this->cache->last_update['departures'])) { foreach ($this->cache->last_update['departures'] as $spoj => $cas) { if ($cas + $cache_expire < time()) { unset($this->cache->departures[$spoj]); unset($this->cache->categories[$spoj]); } } } else { unset($this->cache->departures[$spoj]); unset($this->cache->categories[$spoj]); } if (isset($this->cache->last_update) && isset($this->cache->last_update['stops'])) { foreach ($this->cache->last_update['stops'] as $spoj => $cas) { if ($cas + $cache_expire < time()) { unset($this->cache->stops[$spoj]); } } } else { unset($this->cache->stops[$spoj]); } if (isset($this->cache->stops)) { $this->stops = $this->cache->stops; } if (isset($this->cache->departures)) { $this->departures = $this->cache->departures; } if (isset($this->cache->spoje)) { $this->spoje = $this->cache->spoje; } if (isset($this->cache->form_url)) { $this->form_url = $this->cache->form_url; } if (isset($this->cache->categories)) { $this->categories = $this->cache->categories; } self::online_map(); $this->checkedCache = true; }
function commentListGet() { $cacheFile = new FileCache(); $cacheFile->load('commentlist.json'); if ($cacheFile->needUpdate()) { return commentListGenerate(); } else { return json_decode($cacheFile->read()); } }
function penListGet() { global $srkEnv; $listCache = new FileCache(); $listCache->load('penlist.json'); if ($listCache->needUpdate()) { return penListGenerate(); } else { return json_decode($listCache->read()); } }