Cache more metadatas values

This commit is contained in:
Romain Neutron
2012-06-06 17:46:44 +02:00
parent b5f3a8f5ce
commit 1efeb40a96
2 changed files with 94 additions and 19 deletions

View File

@@ -183,6 +183,9 @@ class caption_Field_Value implements cache_cacheableInterface
$stmt->execute(array(':id' => $this->id));
$stmt->closeCursor();
$this->delete_data_from_cache();
$this->databox_field->delete_data_from_cache();
$sbas_id = $this->record->get_sbas_id();
$this->record->get_caption()->delete_data_from_cache();
@@ -224,6 +227,8 @@ class caption_Field_Value implements cache_cacheableInterface
$this->VocabularyId = $this->VocabularyType = null;
$this->delete_data_from_cache();
return $this;
}
@@ -266,6 +271,8 @@ class caption_Field_Value implements cache_cacheableInterface
$stmt_up->execute($params);
$stmt_up->closeCursor();
$this->delete_data_from_cache();
try {
$registry = registry::get_instance();
$sphinx_rt = sphinxrt::get_instance($registry);
@@ -399,6 +406,7 @@ class caption_Field_Value implements cache_cacheableInterface
$caption_field_value->update_cache_value($value);
$record->get_caption()->delete_data_from_cache();
$this->databox_field->delete_data_from_cache();
return $caption_field_value;
}

View File

@@ -15,7 +15,7 @@
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class caption_field
class caption_field implements cache_cacheableInterface
{
/**
*
@@ -48,21 +48,7 @@ class caption_field
$this->databox_field = $databox_field;
$this->values = array();
$connbas = $databox_field->get_connection();
$sql = 'SELECT id FROM metadatas
WHERE record_id = :record_id
AND meta_struct_id = :meta_struct_id';
$params = array(
':record_id' => $record->get_record_id()
, ':meta_struct_id' => $databox_field->get_id()
);
$stmt = $connbas->prepare($sql);
$stmt->execute($params);
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$rs = $this->get_metadatas_ids();
foreach ($rs as $row) {
$this->values[$row['id']] = new caption_Field_Value($databox_field, $record, $row['id']);
@@ -78,6 +64,35 @@ class caption_field
return $this;
}
protected function get_metadatas_ids()
{
try {
return $this->get_data_from_cache();
} catch (\Exception $e) {
}
$connbas = $this->databox_field->get_connection();
$sql = 'SELECT id FROM metadatas
WHERE record_id = :record_id
AND meta_struct_id = :meta_struct_id';
$params = array(
':record_id' => $this->record->get_record_id()
, ':meta_struct_id' => $this->databox_field->get_id()
);
$stmt = $connbas->prepare($sql);
$stmt->execute($params);
$ids = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$this->set_data_to_cache($ids);
return $ids;
}
/**
*
* @return record_adapter
@@ -439,4 +454,56 @@ class caption_field
return;
}
/**
* Part of the cache_cacheableInterface
*
* @param string $option
* @return string
*/
public function get_cache_key($option = null)
{
return 'caption_field_' . $this->record->get_serialize_key() . ($option ? '_' . $option : '');
}
/**
* Part of the cache_cacheableInterface
*
* @param string $option
* @return mixed
*/
public function get_data_from_cache($option = null)
{
$databox = $this->record->get_databox();
return $databox->get_data_from_cache($this->get_cache_key($option));
}
/**
* Part of the cache_cacheableInterface
*
* @param mixed $value
* @param string $option
* @param int $duration
* @return caption_field
*/
public function set_data_to_cache($value, $option = null, $duration = 360000)
{
$databox = $this->record->get_databox();
return $databox->set_data_to_cache($value, $this->get_cache_key($option), $duration);
}
/**
* Part of the cache_cacheableInterface
*
* @param string $option
* @return caption_field
*/
public function delete_data_from_cache($option = null)
{
$databox = $this->record->get_databox();
return $databox->delete_data_from_cache($this->get_cache_key($option));
}
}