What can cause Drupal cache to be cleared accidentally?
Drupal cache-clearing functions use a
$wildcard variable — when set, they can be used to empty the entire cache. They're commonly used, but can cause a number of problems. Using a wildcard clear with Memcached can cause the accidental clearing of items that you want to remain in the cache.
Accidentally clearing your cache
Contributed modules may use the generic Drupal
cache table. However, a wildcard cache clear causes Memcached to wipe an entire bin. In the case of the
cache_bootstrap table, this forces the variable cache to be rebuilt.
When used incorrectly, two Drupal functions,
variable_set , can also dump all of your cache entries. Any method of clearing the entire cache (including
drush cc all) can have a significant impact on website performance, because every request will have to be fulfilled from the origin server until the cache is rebuilt.
Preventing an accidental cache clear
Checking all cache-clearing calls in your code before deployment is a good start, but it's easy to miss one in the process.
Because of Memcached's architecture, the Memcache module has to treat each wildcard clearing as a purge of an entire bin. For example, if a module uses the main cache bin and does a wildcard clearing of its cache items, the main cache bin is the one that gets purged. The main cache bin includes variables and the schema cache. In a multiserver cluster, this can lock the database.
For websites that you plan to deploy with Memcache, you should audit calls to cache_clear_all ( ). Look for this behavior since performance problems may not be apparent until the website is experiencing live traffic.
If you're using this in your codebase, make sure it's there for a good reason. Documentation on
cache_clear_all for Drupal 7 is available. This function can remove part of your cache, or all of it. This can be extremely useful either when content is updated or when new content is generated, but if this isn't used carefully, you can inadvertently cause website slowness.
$ drush --uri=$SITE cache-clear all
variable_set is here for Drupal 7 .
If you suspect or just want to check to see if there are issues with
variable_set, you can use some debugging code to watch what this function is doing.