/** * Stores value by key. * * @param string $key Cache key. * @param mixed $value Cache value. * @param integer $expire Expire time, in seconds(optional). * * @access public * @uses Core\Modules\DB\Query * * @return boolean */ public function store($key, $value, $expire = 0) { if ($expire) { $expire = time() + $expire; } $value = json_encode($value); $query = new Query(); $exists = $query->select('all')->from($this->tableName)->where("{$this->fields[0]} = ?", array(md5($key)))->first(); if (is_null($exists)) { $insert = $query->insert($this->fields, array(md5($key), $value, $expire))->into($this->tableName); return Core\DB()->run($insert); } else { $update = $query->update($this->tableName)->set($this->fields, array(md5($key), $value, $expire))->where("{$this->fields[0]} = ?", array(md5($key))); return Core\DB()->run($update); } }
/** * Updates the record in the database. * * @access private * * @return boolean */ private function update() { list($fields, $values) = $this->extractFields(); $query = new DB\Query(); $this->query = $query->update(static::$tableName)->set($fields, $values)->where(static::$primaryKeyField . ' = ?', array($this->{static::$primaryKeyField})); if (static::$isI18n) { $query_i18n = new DB\Query(); $i18n_existing_record = $query_i18n->select(static::$i18nLocaleField)->from(static::$i18nTableName)->where(static::$i18nForeignKeyField . ' = ' . $this->{static::$primaryKeyField} . ' AND ' . static::$i18nLocaleField . ' = "' . static::$i18nLocale . '"')->first(); if (!$i18n_existing_record) { list($fields, $values) = $this->extractFieldsI18n(true); $query_i18n = $query_i18n->insert($fields, $values)->into(static::$i18nTableName); } else { list($fields, $values) = $this->extractFieldsI18n(); $query_i18n = $query_i18n->update(static::$i18nTableName)->set($fields, $values)->where(static::$i18nForeignKeyField . ' = ' . $this->{static::$primaryKeyField} . ' AND ' . static::$i18nLocaleField . ' = "' . static::$i18nLocale . '"'); } return Core\DB()->run($this->query) && Core\DB()->run($query_i18n); } return Core\DB()->run($this->query); }