table_name, 'default'); } public function setValue($productId, $key, $value) { $cache = load_cache(); $data = [ 'product_id' => $productId, 'name' => $key, 'value' => is_array($value) ? json_encode($value,JSON_UNESCAPED_UNICODE) : $value, ]; $this->replace($data); $cache->delete(sprintf($this->cacheKey, $productId, $key)); } public function getValue($productId, $name) { $cache = load_cache(); $cacheKey = sprintf($this->cacheKey, $productId, $name); $result = $cache->get($cacheKey); if (!$cache->exists($cacheKey)) { $row = $this->get(['product_id' => $productId, 'name' => $name]); $result = $row['value']; $cache->save($cacheKey, $result, 2*3600); } return $result; } }