Skip to content

Commit

Permalink
DB cleanup is required not optional
Browse files Browse the repository at this point in the history
  • Loading branch information
rachelwhitton committed Feb 3, 2025
1 parent 9079fb3 commit 9ab57f8
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 18 deletions.
37 changes: 20 additions & 17 deletions source/content/addons/object-cache/howto/drupal.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Enable Object Cache for Drupal
description: How to install and configure Object Cache for Drupal.
permalink: docs/object-cache/drupal
tags: [cache, plugins, modules, database]
reviewed: "2023-08-17"
reviewed: "2025-02-03"
contenttype: [doc]
innav: [true]
categories: [cache]
Expand Down Expand Up @@ -119,25 +119,32 @@ contributors: [cityofoaksdesign, carolynshannon, jms-pantheon, whitneymeredith]

</Alert>

<Accordion title="Database Cleanup (recommended)" id="database-cleanup-drupal" icon="lightbulb">
### Database Cleanup (Required)

After enabling Redis, there are cache tables in the database that are no longer being used. Even when the Drupal cache is cleared, these tables will not be emptied. For sites that were live for awhile before Redis was enabled, there could be significant amounts of data in these tables. Removing this data could increase the speed of cloning, exporting, and backing up the database.

1. [Connect directly to MySQL](/guides/mariadb-mysql/mysql-access) and run the command below to view the cache:
Use the following script to cleanup cache tables in the database:

```sql
SELECT table_name FROM information_schema.tables WHERE table_name LIKE 'cache%' AND table_name != 'cache_form';
```
<Download file="drupal-db-cleanup-cache-tables.sh" />

This returns a list of all the cache tables in the database. These are safe to empty, but don't remove the tables themselves in case Redis is disabled in the future.
```bash
#!/bin/bash

1. Run the command below on each table, replacing `<tablename>` with the name of the cache table, to empty the cache:
echo 'Provide the site name (e.g. your-awesome-site), then press [ENTER]:';
read SITE;

```sql
TRUNCATE TABLE `<tablename>`;
```
echo 'Provide the site name (multidev, dev, test, or live), then press [ENTER]:';
read ENV;

# Get a list of all cache tables
CACHETABLES="$(terminus drush $SITE.$ENV -- sql:query "SHOW TABLES LIKE 'cache%';")"

</Accordion>
# Trucate each cache table in a loop to avoid resource contention and potential deadlocks.

for table in $CACHETABLES; do
terminus drush $SITE.$ENV -- sql:query "TRUNCATE TABLE $table;"
done
```

## Drupal 7

Expand Down Expand Up @@ -188,11 +195,7 @@ This configuration uses the `Redis_CacheCompressed` class for better performance

1. Visit `/admin/config/development/performance/redis` and open **Connection Information** to verify the connection.

<Accordion title="Database Cleanup (recommended)" id="database-cleanup-d7" icon="lightbulb">

After enabling Redis, there are cache tables in the database that are no longer being used. Refer to the "Database Cleanup" section above for steps on how to truncate the existing cache tables to make sure the latest data populates object cache properly.

</Accordion>
1. See the ["Database Cleanup" section above](#database-cleanup-required) for steps on how to truncate the existing cache tables to make sure the latest data populates object cache properly.


## More Resources
Expand Down
29 changes: 28 additions & 1 deletion source/content/addons/object-cache/howto/wordpress.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,32 @@ terminus redis:enable <site>

</Alert>

### Database Cleanup (Required)
After enabling Redis, there are cache tables in the database that are no longer being used. Even when the Drupal cache is cleared, these tables will not be emptied. For sites that were live for awhile before Redis was enabled, there could be significant amounts of data in these tables. Removing this data could increase the speed of cloning, exporting, and backing up the database.

Use the following script to cleanup cache tables in the database:

<Download file="wp-db-cleanup-cache-tables.sh" />

```bash
#!/bin/bash
echo 'Provide the site name (e.g. your-awesome-site), then press [ENTER]:';
read SITE;
echo 'Provide the site name (multidev, dev, test, or live), then press [ENTER]:';
read ENV;
# Get a list of all cache tables
CACHETABLES="$(terminus wp $SITE.$ENV -- db query "SHOW TABLES LIKE 'cache%';")"
# Trucate each cache table in a loop to avoid resource contention and potential deadlocks.
for table in $CACHETABLES; do
terminus wp $SITE.$ENV -- db query "TRUNCATE TABLE $table;"
done
```

## Installation and Configuration for Composer-Managed WordPress Sites

Refer to the [official Object Cache Pro documentation](https://objectcache.pro/docs/composer-installation) for full configuration instructions.
Expand Down Expand Up @@ -223,7 +249,6 @@ Refer to the [official Object Cache Pro documentation](https://objectcache.pro/d
] );
```
1. Add Object Cache Pro configuration options after `Config::define( 'WP_REDIS_CONFIG', [` in `config/application.php` for **WordPress (Composer Managed)** sites. The full, recommended contents of the WP_REDIS_CONFIG constant are:
```php
Expand Down Expand Up @@ -291,6 +316,8 @@ Refer to the [official Object Cache Pro documentation](https://objectcache.pro/d
- If you are using WordPress Multisite, subsites do not get their own configuration or graphs. Navigate to `/wp-admin/network/settings.php?page=objectcache` to view network-wide configuration and graphs. This is the only screen throughout the network that displays this information.
1. See the ["Database Cleanup" section above](#database-cleanup-required) for steps on how to truncate the existing cache tables to make sure the latest data populates object cache properly.
## Local configuration with Lando
Lando's [Pantheon recipe](https://docs.lando.dev/plugins/pantheon/) includes Redis in its Docker configuration. However, to get Object Cache Pro to work correctly with Lando locally, you'll need to make a few changes to your Object Cache Pro and Lando configuration.
Expand Down
16 changes: 16 additions & 0 deletions source/scripts/drupal-db-cleanup-cache-tables.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

echo 'Provide the site name (e.g. your-awesome-site), then press [ENTER]:';
read SITE;

echo 'Provide the site name (multidev, dev, test, or live), then press [ENTER]:';
read ENV;

# Get a list of all cache tables
CACHETABLES="$(terminus drush $SITE.$ENV -- sql:query "SHOW TABLES LIKE 'cache%';")"

# Trucate each cache table in a loop to avoid resource contention and potential deadlocks.

for table in $CACHETABLES; do
terminus drush $SITE.$ENV -- sql:query "TRUNCATE TABLE $table;"
done
16 changes: 16 additions & 0 deletions source/scripts/wp-db-cleanup-cache-tables.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

echo 'Provide the site name (e.g. your-awesome-site), then press [ENTER]:';
read SITE;

echo 'Provide the site name (multidev, dev, test, or live), then press [ENTER]:';
read ENV;

# Get a list of all cache tables
CACHETABLES="$(terminus wp $SITE.$ENV -- db query "SHOW TABLES LIKE 'cache%';")"

# Trucate each cache table in a loop to avoid resource contention and potential deadlocks.

for table in $CACHETABLES; do
terminus wp $SITE.$ENV -- db query "TRUNCATE TABLE $table;"
done

0 comments on commit 9ab57f8

Please sign in to comment.