Commit 87462db6 authored by catch's avatar catch

Issue #1167144 by chx, catch, claudiu.cristea: Make cache backends responsible...

Issue #1167144 by chx, catch, claudiu.cristea: Make cache backends responsible for their own storage.
parent 2508db12
......@@ -5,9 +5,11 @@
* API for loading and interacting with Drupal modules.
*/
use Drupal\Component\Graph\Graph;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Yaml\Parser;
/**
* Builds a list of bootstrap modules and enabled modules and themes.
......@@ -566,7 +568,6 @@ function module_uninstall($module_list = array(), $uninstall_dependents = TRUE)
$module_list = array_keys($module_list);
}
$storage = drupal_container()->get('config.storage');
$schema_store = Drupal::keyValue('system.schema');
$disabled_config = config('system.module.disabled');
foreach ($module_list as $module) {
......@@ -578,6 +579,38 @@ function module_uninstall($module_list = array(), $uninstall_dependents = TRUE)
// Remove all configuration belonging to the module.
config_uninstall_default_config('module', $module);
// Remove any cache bins defined by the module.
$service_yaml_file = drupal_get_path('module', $module) . "/$module.services.yml";
if (file_exists($service_yaml_file)) {
$parser = new Parser;
$definitions = $parser->parse(file_get_contents($service_yaml_file));
if (isset($definitions['services'])) {
foreach ($definitions['services'] as $id => $definition) {
if (isset($definition['tags'])) {
foreach ($definition['tags'] as $tag) {
// This works for the default cache registration and even in some
// cases when a non-default "super" factory is used. That should
// be extremely rare.
if ($tag['name'] == 'cache.bin' && isset($definition['factory_service']) && isset($definition['factory_method']) && !empty($definition['arguments'])) {
try {
$factory = Drupal::service($definition['factory_service']);
if (method_exists($factory, $definition['factory_method'])) {
$backend = call_user_func_array(array($factory, $definition['factory_method']), $definition['arguments']);
if ($backend instanceof CacheBackendInterface) {
$backend->removeBin();
}
}
}
catch (Exception $e) {
watchdog_exception('system', $e, 'Failed to remove cache bin defined by the service %id.', array('%id' => $id));
}
}
}
}
}
}
}
watchdog('system', '%module module uninstalled.', array('%module' => $module), WATCHDOG_INFO);
$schema_store->delete($module);
$disabled_config->clear($module);
......
......@@ -222,4 +222,14 @@ public function isEmpty() {
return TRUE;
}
/**
* {@inheritdoc}
*/
public function removeBin() {
foreach ($this->backends as $backend) {
$this->removeBin();
}
}
}
......@@ -286,6 +286,11 @@ public function invalidateAll();
*/
public function garbageCollection();
/**
* Remove a cache bin.
*/
public function removeBin();
/**
* Checks if a cache bin is empty.
*
......
......@@ -215,4 +215,10 @@ public function isEmpty() {
*/
public function garbageCollection() {
}
/**
* {@inheritdoc}
*/
public function removeBin() {}
}
......@@ -98,4 +98,9 @@ public function garbageCollection() {}
public function isEmpty() {
return TRUE;
}
/**
* {@inheritdoc}
*/
public function removeBin() {}
}
......@@ -480,7 +480,7 @@ public function prepareComment($comment, $length = NULL) {
// Truncate comment to maximum comment length.
if (isset($length)) {
// Add table prefixes before truncating.
$comment = truncate_utf8($this->connection->prefixTables($comment), $length, TRUE, TRUE);
$comment = substr($this->connection->prefixTables($comment), 0, $length);
}
return $this->connection->quote($comment);
......
......@@ -6,17 +6,6 @@
*/
use Drupal\Component\Uuid\Uuid;
/**
* Implements hook_schema().
*/
function block_schema() {
$schema['cache_block'] = drupal_get_schema_unprocessed('system', 'cache');
$schema['cache_block']['description'] = 'Cache table for the Block module to store already built blocks, identified by module, delta, and various contexts which may change the block, such as theme, locale, and caching mode defined for the block.';
return $schema;
}
/**
* Implements hook_install().
*/
......
......@@ -8,16 +8,6 @@
use Drupal\Component\Uuid\Uuid;
use Drupal\field\Plugin\Core\Entity\Field;
/**
* Implements hook_schema().
*/
function field_schema() {
$schema['cache_field'] = drupal_get_schema_unprocessed('system', 'cache');
$schema['cache_field']['description'] = 'Cache table for the Field module to store already built field informations.';
return $schema;
}
/**
* Creates a field by writing directly to the database.
*
......
......@@ -7,16 +7,6 @@
use Drupal\Component\Uuid\Uuid;
/**
* Implements hook_schema().
*/
function filter_schema() {
$schema['cache_filter'] = drupal_get_schema_unprocessed('system', 'cache');
$schema['cache_filter']['description'] = 'Cache table for the Filter module to store already filtered pieces of text, identified by text format and hash of the text.';
return $schema;
}
/**
* @addtogroup updates-7.x-to-8.x
* @{
......
......@@ -143,8 +143,7 @@ function testFilterAdmin() {
$this->drupalGet('admin/config/content/formats/' . $basic);
$this->assertFieldByName('filters[filter_html][settings][allowed_html]', $edit['filters[filter_html][settings][allowed_html]'], 'Allowed HTML tag added.');
$result = db_query('SELECT * FROM {cache_filter}')->fetchObject();
$this->assertFalse($result, 'Cache cleared.');
$this->assertTrue(cache('filter')->isEmpty(), 'Cache cleared.');
$elements = $this->xpath('//select[@name=:first]/following::select[@name=:second]', array(
':first' => 'filters[' . $first_filter . '][weight]',
......
......@@ -40,17 +40,4 @@ protected function createCacheBackend($bin) {
return new DatabaseBackend($this->container->get('database'), $bin);
}
/**
* Installs system schema.
*/
public function setUpCacheBackend() {
$this->installSchema('system', array('cache', 'cache_page', 'cache_tags', 'cache_path', 'cache_bootstrap'));
}
/**
* Uninstalls system schema.
*/
public function tearDownCacheBackend() {
drupal_uninstall_schema('system');
}
}
......@@ -1934,12 +1934,12 @@ function hook_mail($key, &$message, $params) {
/**
* Flush all persistent and static caches.
*
* This hook asks your module to clear all of its persistent (database) and
* static caches, in order to ensure a clean environment for subsequently
* This hook asks your module to clear all of its static caches,
* in order to ensure a clean environment for subsequently
* invoked data rebuilds.
*
* Do NOT use this hook for rebuilding information. Only use it to flush custom
* caches and return the names of additional cache bins to flush.
* caches.
*
* Static caches using drupal_static() do not need to be reset manually.
* However, all other static variables that do not use drupal_static() must be
......
......@@ -597,102 +597,6 @@ function system_schema() {
),
);
$schema['cache_tags'] = array(
'description' => 'Cache table for tracking cache tags related to the cache bin.',
'fields' => array(
'tag' => array(
'description' => 'Namespace-prefixed tag string.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'invalidations' => array(
'description' => 'Number incremented when the tag is invalidated.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'deletions' => array(
'description' => 'Number incremented when the tag is deleted.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('tag'),
);
$schema['cache'] = array(
'description' => 'Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.',
'fields' => array(
'cid' => array(
'description' => 'Primary Key: Unique cache ID.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'data' => array(
'description' => 'A collection of data to cache.',
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
),
'expire' => array(
'description' => 'A Unix timestamp indicating when the cache entry should expire, or 0 for never.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'created' => array(
'description' => 'A Unix timestamp indicating when the cache entry was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'serialized' => array(
'description' => 'A flag to indicate whether content is serialized (1) or not (0).',
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'default' => 0,
),
'tags' => array(
'description' => 'Space-separated list of cache tags for this entry.',
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
),
'checksum_invalidations' => array(
'description' => 'The tag invalidation sum when this entry was saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'checksum_deletions' => array(
'description' => 'The tag deletion sum when this entry was saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'expire' => array('expire'),
),
'primary key' => array('cid'),
);
$schema['cache_bootstrap'] = $schema['cache'];
$schema['cache_bootstrap']['description'] = 'Cache table for data required to bootstrap Drupal, may be routed to a shared memory cache.';
$schema['cache_config'] = $schema['cache'];
$schema['cache_config']['description'] = 'Cache table for configuration data.';
$schema['cache_page'] = $schema['cache'];
$schema['cache_page']['description'] = 'Cache table used to store compressed pages for anonymous users, if page caching is enabled.';
$schema['cache_menu'] = $schema['cache'];
$schema['cache_menu']['description'] = 'Cache table for the menu system to store router information as well as generated link trees for various menu/page/user combinations.';
$schema['cache_path'] = $schema['cache'];
$schema['cache_path']['description'] = 'Cache table for path alias lookup.';
$schema['flood'] = array(
'description' => 'Flood controls the threshold of events, such as the number of contact attempts.',
'fields' => array(
......
<?php
/**
* @file
* Install, update and uninstall functions for the cache_test module.
*/
/**
* Implements hook_schema().
*/
function cache_test_schema() {
$schema['cache_test'] = drupal_get_schema_unprocessed('system', 'cache');
$schema['cache_test']['description'] = 'Cache table for testing the cache system.';
return $schema;
}
......@@ -5,36 +5,18 @@
* Install, update and uninstall functions for the toolbar module.
*/
/**
* Implements hook_schema().
*/
function toolbar_schema() {
$schema['cache_toolbar'] = drupal_get_schema_unprocessed('system', 'cache');
$schema['cache_toolbar']['description'] = 'Cache table for the Toolbar module to store per-user hashes of rendered toolbar subtrees.';
return $schema;
}
/**
* @addtogroup updates-7.x-to-8.x
* @{
*/
/**
* Creates the {cache_toolbar} cache table.
*/
function toolbar_update_8000() {
$schema['cache_toolbar'] = drupal_get_schema_unprocessed('system', 'cache');
$schema['cache_toolbar']['description'] = 'Cache table for the Toolbar module to store per-user hashes of rendered toolbar subtrees.';
db_create_table('cache_toolbar', $schema['cache_toolbar']);
}
/**
* Enable the Breakpoint and Config modules.
*
* The 7.x version of the Toolbar module had no dependencies. The 8.x version
* depends on the Breakpoint and Configuration manager modules.
*/
function toolbar_update_8001() {
function toolbar_update_8000() {
// Enable the modules without re-installing the schema.
update_module_enable(array('breakpoint'));
}
......
......@@ -14,19 +14,6 @@ function views_install() {
module_set_weight('views', 10);
}
/**
* Implements hook_schema().
*/
function views_schema() {
$schema['cache_views_info'] = drupal_get_schema_unprocessed('system', 'cache');
$schema['cache_views_results'] = drupal_get_schema_unprocessed('system', 'cache');
$schema['cache_views_results']['description'] = 'Cache table for views to store pre-rendered queries, results, and display output.';
$schema['cache_views_results']['fields']['serialized']['default'] = 1;
return $schema;
}
/**
* Provide an initial schema.
*
......
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