Commit db72be76 authored by alexpott's avatar alexpott

Issue #2302843 by claudiu.cristea: {cache_tags} conflicts with cache bin database table names.

parent 2c93dd67
......@@ -324,14 +324,14 @@ public function deleteTags(array $tags) {
$deleted_tags[$tag] = TRUE;
unset($tag_cache[$tag]);
try {
$this->connection->merge('cache_tags')
$this->connection->merge('cachetags')
->insertFields(array('deletions' => 1))
->expression('deletions', 'deletions + 1')
->key('tag', $tag)
->execute();
}
catch (\Exception $e) {
$this->catchException($e, 'cache_tags');
$this->catchException($e, 'cachetags');
}
}
}
......@@ -393,7 +393,7 @@ public function invalidateTags(array $tags) {
}
$invalidated_tags[$tag] = TRUE;
unset($tag_cache[$tag]);
$this->connection->merge('cache_tags')
$this->connection->merge('cachetags')
->insertFields(array('invalidations' => 1))
->expression('invalidations', 'invalidations + 1')
->key('tag', $tag)
......@@ -401,7 +401,7 @@ public function invalidateTags(array $tags) {
}
}
catch (\Exception $e) {
$this->catchException($e, 'cache_tags');
$this->catchException($e, 'cachetags');
}
}
......@@ -485,7 +485,7 @@ protected function checksumTags($flat_tags) {
$query_tags = array_diff($flat_tags, array_keys($tag_cache));
if ($query_tags) {
$db_tags = $this->connection->query('SELECT tag, invalidations, deletions FROM {cache_tags} WHERE tag IN (:tags)', array(':tags' => $query_tags))->fetchAllAssoc('tag', \PDO::FETCH_ASSOC);
$db_tags = $this->connection->query('SELECT tag, invalidations, deletions FROM {cachetags} WHERE tag IN (:tags)', array(':tags' => $query_tags))->fetchAllAssoc('tag', \PDO::FETCH_ASSOC);
$tag_cache += $db_tags;
// Fill static cache with empty objects for tags not found in the database.
......@@ -522,8 +522,8 @@ protected function ensureBinExists() {
$schema_definition = $this->schemaDefinition();
$database_schema->createTable($this->bin, $schema_definition['bin']);
// If the bin doesn't exist, the cache tags table may also not exist.
if (!$database_schema->tableExists('cache_tags')) {
$database_schema->createTable('cache_tags', $schema_definition['cache_tags']);
if (!$database_schema->tableExists('cachetags')) {
$database_schema->createTable('cachetags', $schema_definition['cachetags']);
}
return TRUE;
}
......@@ -540,14 +540,14 @@ protected function ensureBinExists() {
/**
* Act on an exception when cache might be stale.
*
* If the cache_tags table does not yet exist, that's fine but if the table
* If the {cachetags} table does not yet exist, that's fine but if the table
* exists and yet the query failed, then the cache is stale and the
* exception needs to propagate.
*
* @param $e
* The exception.
* @param string|null $table_name
* The table name, defaults to $this->bin. Can be cache_tags.
* The table name, defaults to $this->bin. Can be cachetags.
*/
protected function catchException(\Exception $e, $table_name = NULL) {
if ($this->connection->schema()->tableExists($table_name ?: $this->bin)) {
......@@ -576,7 +576,7 @@ protected function normalizeCid($cid) {
}
/**
* Defines the schema for the cache bin and cache_tags table.
* Defines the schema for the {cache_*} bin and {cachetags} tables.
*/
public function schemaDefinition() {
$schema['bin'] = array(
......@@ -640,7 +640,7 @@ public function schemaDefinition() {
),
'primary key' => array('cid'),
);
$schema['cache_tags'] = array(
$schema['cachetags'] = array(
'description' => 'Cache table for tracking cache tags related to the cache bin.',
'fields' => array(
'tag' => array(
......
......@@ -48,7 +48,7 @@ public function testTagInvalidations() {
$this->assertTrue($bin->get('test'), 'Cache item was set in bin.');
}
$invalidations_before = intval(db_select('cache_tags')->fields('cache_tags', array('invalidations'))->condition('tag', 'test_tag:2')->execute()->fetchField());
$invalidations_before = intval(db_select('cachetags')->fields('cachetags', array('invalidations'))->condition('tag', 'test_tag:2')->execute()->fetchField());
Cache::invalidateTags(array('test_tag' => array(2)));
// Test that cache entry has been invalidated in multiple bins.
......@@ -58,7 +58,7 @@ public function testTagInvalidations() {
}
// Test that only one tag invalidation has occurred.
$invalidations_after = intval(db_select('cache_tags')->fields('cache_tags', array('invalidations'))->condition('tag', 'test_tag:2')->execute()->fetchField());
$invalidations_after = intval(db_select('cachetags')->fields('cachetags', array('invalidations'))->condition('tag', 'test_tag:2')->execute()->fetchField());
$this->assertEqual($invalidations_after, $invalidations_before + 1, 'Only one addition cache tag invalidation has occurred after invalidating a tag used in multiple bins.');
}
......@@ -72,7 +72,7 @@ public function testTagDeletetions() {
$this->assertTrue($bin->get('test'), 'Cache item was set in bin.');
}
$deletions_before = intval(db_select('cache_tags')->fields('cache_tags', array('deletions'))->condition('tag', 'test_tag:2')->execute()->fetchField());
$deletions_before = intval(db_select('cachetags')->fields('cachetags', array('deletions'))->condition('tag', 'test_tag:2')->execute()->fetchField());
Cache::deleteTags(array('test_tag' => array(2)));
// Test that cache entry has been deleted in multiple bins.
......@@ -82,7 +82,7 @@ public function testTagDeletetions() {
}
// Test that only one tag deletion has occurred.
$deletions_after = intval(db_select('cache_tags')->fields('cache_tags', array('deletions'))->condition('tag', 'test_tag:2')->execute()->fetchField());
$deletions_after = intval(db_select('cachetags')->fields('cachetags', array('deletions'))->condition('tag', 'test_tag:2')->execute()->fetchField());
$this->assertEqual($deletions_after, $deletions_before + 1, 'Only one addition cache tag deletion has occurred after deleting a tag used in multiple bins.');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment