Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
global $conf;
$result = db_query("SHOW TABLES LIKE 'cache%'");
while ($table_name = db_result($result)) {
if ($table_name == 'cache_form' || (!empty($conf['memcache_bins'][$table_name]) && $conf['memcache_bins'][$table_name] == 'database')) {
echo t('%name NOT truncated.', array('%name' => $table_name)) . "<br>\n";
continue;
}
db_query("TRUNCATE TABLE %s", $table_name);
echo t('%name truncated.', array('%name' => $table_name)) . "<br>\n";
}
Want to reduce the size of our database backups. Data is still in the db tables even after turning on memcache.
Comment | File | Size | Author |
---|---|---|---|
#3 | memcache-truncate-cache-1507640-3.patch | 789 bytes | markpavlitski |
Comments
Comment #1
doublejosh CreditAttribution: doublejosh commentedWould be very nice to have a utility button to "Clear Leftover Database Cache" within admin settings.
Personally, was having problems with database backups on local dev environments, and it took a while to realize why. Assume there are plenty of other weird consequences like this when moving between environments. #1896142: PHP Fatal error: Unsupported operand types
Mikeytown2's point about reducing database backup size is also certainly a valid reason.
BTW: Here's how to do this from the command line...
mysql -uUSER -pPASS --execute="SELECT concat('TRUNCATE TABLE ', TABLE_NAME, ';') FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'DB_NAME' AND TABLE_NAME LIKE 'cache%'" | sed 1d | mysql -uUSER -pPASS DB_NAME
Change: USER, PASS, and DB_NAME
Comment #2
doublejosh CreditAttribution: doublejosh commentedComment #3
markpavlitski CreditAttribution: markpavlitski commentedI can't see this feature making it into memcache, however this patch adds a note to README.txt telling users how to clear these tables manually.
Comment #4
doublejosh CreditAttribution: doublejosh commentedAt least it's documented :)
Might mention the technique for clearing all cache tables at once with one command. Each person who enables Memcache on an existing site will have to go through this step, and I assume most sites don't start out with in-memory caching.
Comment #4.0
doublejosh CreditAttribution: doublejosh commentedUpdated issue summary.
Comment #5
Jeremy CreditAttribution: Jeremy commentedI wouldn't be opposed to seeing this go in as a drush command, together with functionality like #1993170: Add Drush command to retrieve Memcached values. It'll land after 7.x-1.1 is released.
Comment #6
Jeremy CreditAttribution: Jeremy at Tag1 Consulting commentedNot really a memcache feature, closing.