Skip to content

Commit

Permalink
fixup! Added Redis
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoltan committed Feb 5, 2019
1 parent 9e4866a commit fb05a30
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/CBX/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public function fetchConfig($language, $domain) {

public function fetchCollection($url) {
if ($url) {
$cachedData = $this->cache->get($url);
$cacheKey = 'cbx-i18n-online-'.md5($url);
$cachedData = $this->cache->get($cacheKey);
if ($cachedData) {
if (gettype($cachedData) === "string") {
$json = json_decode(trim($cachedData), true);
Expand All @@ -41,7 +42,7 @@ public function fetchCollection($url) {
}
$data = $this->fetch($url);
if ($data) {
$this->cache->set($url, gettype($data) === "string" ? $data : json_encode($data));
$this->cache->set($cacheKey, gettype($data) === "string" ? $data : json_encode($data));
}
return $data;
}
Expand Down
24 changes: 23 additions & 1 deletion src/CBX/APIOffline.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,29 @@ public function fetchConfig($language, $domain) {
}

public function fetchCollection($file) {
return $this->fetch($this->dir.'/'.$file);
if ($file) {
$path = $this->dir.'/'.$file;
$cacheKey = 'cbx-i18n-offline-'.md5($path);
$cachedData = $this->cache->get($cacheKey);
if ($cachedData) {
if (gettype($cachedData) === "string") {
$json = json_decode(trim($cachedData), true);
if (json_last_error() === 0) {
return $json;
} else {
throw new \Exception("I18NClass API Error. Collection JSON. ".json_last_error_msg());
}
} else {
return $cachedData;
}
}
$data = $this->fetch($path);
if ($data) {
$this->cache->set($cacheKey, gettype($data) === "string" ? $data : json_encode($data));
}
return $data;
}
return false;
}

private function fetch($path) {
Expand Down

0 comments on commit fb05a30

Please sign in to comment.