apc = $apc; $this->prefix = (string)$prefix; $this->ttl = (int)$ttl; } public function key($type, $langId) { return $this->prefix . $this->normalizeType($type) . '_LANG_' . (int)$langId; } public function get($type, $langId) { if (!$this->apc->enabled) { return false; } $cached = $this->apc->check($this->key($type, $langId)); if (!is_array($cached) || !array_key_exists('payload', $cached)) { return false; } return $cached['payload']; } public function set($type, $langId, $data, $ttl = null) { if (!$this->apc->enabled) { return false; } $this->apc->store($this->key($type, $langId), ['payload' => $data], ($ttl !== null ? (int)$ttl : $this->ttl)); return true; } public function delete($type, $langId) { if (!$this->apc->enabled) { return false; } $this->apc->setExpired($this->key($type, $langId)); return true; } private function normalizeType($type) { if (is_array($type)) { $type = array_map('strval', $type); sort($type, SORT_STRING); return implode('_', $type); } return (string)$type; } }