db = \Query($this->db_config['collection']); } catch (\PDOException $e) { $this->valid_database = FALSE; return FALSE; } } /** * Retreive a value from the cache backend * * @param string $key * @return mixed */ public function get($key) { $query = $this->db->select('value') ->from('cache') ->where('key', $key) ->get(); $row = $query->fetch(\PDO::FETCH_ASSOC); if ( ! empty($row)) { return unserialize($row['value']); } return NULL; } /** * Set a cached value * * @param string $key * @param mixed $value * @return CacheDriverInterface */ public function set($key, $value) { $this->db->set([ 'key' => $key, 'value' => serialize($value), ]); /*if ( ! empty($this->get($key))) { $this->db->update('cache'); } else*/ { $this->db->insert('cache'); } return $this; } /** * Invalidate a cached value * * @param string $key * @return CacheDriverInterface */ public function invalidate($key) { $this->db->where('key', $key) ->delete('cache'); return $this; } } // End of SQLDriver.php