How to recover from a borked cache? The following steps lead to a situation where drush cc all would fail.


Build a site, with fields and stuff. Especially one or some fields for the user entity.
Install an alternative cache plugin, e.g. mongodb.
Change the site configuration. E.g. remove one of the fields on user entity.
Disable the alternative cache plugin, switch back to database cache.


Now the database cache contains really old data (or this is how I imagine it), still referencing fields that have long been deleted.

On drush cc all, drush first wants to bootstrap Drupal. Doing this, it also tries to load a user account for login. This lets it use cached data for user fields.

I get a crash with mysql exception from field_sql_storage_field_storage_load(), because it tries to load non-existing fields.

I suppose this is just one example for a site being broked due to really old cache data, after switching the cache plugin.

How can one recover from this situation?
For me the following hack worked:


Edit includes/cache.inc. Let function cache_get() return FALSE.
Run drush cc all.
Revert the hack in includes/cache.inc.


I am not saying this is the best solution. But it did work for me, on a dev system. I am not sure I would recommend this on a production system.

Here is the hack:

 function cache_get($cid, $bin = 'cache') {
+  return FALSE;
+  # return _cache_get_object($bin)-&gt;get($cid);
-  return _cache_get_object($bin)-&gt;get($cid);
 }