With authcache enabled, cache_page in memcache doesn't get cleared by drush cc all
To verify this, I've tested 4 scenarios (in all cases anon page caching set to be handled by Drupal core).
1) cache_page in the db (no authcache or memcache)
Result: cc all removes cache_page entries
2) cache_page in memcache (no authcache)
Result: cc all removes cache_page entries
3) cache_page in memcache with authcache enabled
Result: cc all DOES NOT remove cache_page entries
4) cache_page in the db with memcache and authcache enabled
Result: cc all removes cache_page entries
This is not a case of leaving an expired entry in the cache bin (as cache_get will return expired entries, see https://drupal.org/node/534092), as the expiry date is in the future. It seems that authcache is preventing the cache_page being cleared.
Here are the actual tests; I'm checking for the presence of an entry in cache_page, but we only want to see the metadata so the actual cache entry itself's being thrown away.
1) cache_page in the db (no authcache or memcache)
Test:
mcdruid@ubuntu-lucid:~> drush @d7sand cc all
'all' cache was cleared in d7sand [success]
mcdruid@ubuntu-lucid:~> drush @d7sand ev '$cached_page = cache_get("http://d7sandbox.lucid/", "cache_page"); unset($cached_page->data); if (is_numeric($cached_page->created)) { $cached_page->created_h = date('r', $cached_page->created); $cached_page->expire_h = date('r', $cached_page->expire); } else { $cached_page = "no cache entry\n"; } print_r($cached_page); ';
no cache entry
mcdruid@ubuntu-lucid:~> curl -sIXGET http://d7sandbox.lucid/
HTTP/1.1 200 OK
Date: Sat, 08 Jun 2013 09:32:17 GMT
Server: Apache/2.2.14 (Ubuntu)
X-Powered-By: PHP/5.3.2-1ubuntu4.18
X-Drupal-Cache: MISS
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified: Sat, 08 Jun 2013 09:32:17 +0000
Cache-Control: public, max-age=300
ETag: "1370683937-0"
Content-Language: en
X-Generator: Drupal 7 (http://drupal.org)
Vary: Cookie,Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8
mcdruid@ubuntu-lucid:~> drush @d7sand ev '$cached_page = cache_get("http://d7sandbox.lucid/", "cache_page"); unset($cached_page->data); if (is_numeric($cached_page->created)) { $cached_page->created_h = date('r', $cached_page->created); $cached_page->expire_h = date('r', $cached_page->expire); } else { $cached_page = "no cache entry\n"; } print_r($cached_page); ';
stdClass Object
(
[cid] => http://d7sandbox.lucid/
[created] => 1370683937
[expire] => -1
[serialized] => 1
[created_h] => Sat, 08 Jun 2013 10:32:17 +0100
[expire_h] => Thu, 01 Jan 1970 00:59:59 +0100
)
mcdruid@ubuntu-lucid:~> drush @d7sand cc all
'all' cache was cleared in d7sand [success]
mcdruid@ubuntu-lucid:~> drush @d7sand ev '$cached_page = cache_get("http://d7sandbox.lucid/", "cache_page"); unset($cached_page->data); if (is_numeric($cached_page->created)) { $cached_page->created_h = date('r', $cached_page->created); $cached_page->expire_h = date('r', $cached_page->expire); } else { $cached_page = "no cache entry\n"; } print_r($cached_page); ';
no cache entry
mcdruid@ubuntu-lucid:~>
Result: cc all removes cache_page entries
2) cache_page in memcache (no authcache)
config in settings.php
$conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';
//$conf['cache_backends'][] = 'sites/all/modules/authcache/authcache.inc';
$conf['cache_class_cache_page'] = 'MemCacheDrupal';
$conf['cache_class_cache_form'] = 'DrupalDatabaseCache';
$conf['cache_default_class'] = 'MemCacheDrupal';
Test:
mcdruid@ubuntu-lucid:~> drush @d7sand cc all
'all' cache was cleared in d7sand [success]
mcdruid@ubuntu-lucid:~> drush @d7sand ev '$cached_page = cache_get("http://d7sandbox.lucid/", "cache_page"); unset($cached_page->data); if (is_numeric($cached_page->created)) { $cached_page->created_h = date('r', $cached_page->created); $cached_page->expire_h = date('r', $cached_page->expire); } else { $cached_page = "no cache entry\n"; } print_r($cached_page); ';
no cache entry
mcdruid@ubuntu-lucid:~> curl -sIXGET http://d7sandbox.lucid/
HTTP/1.1 200 OK
Date: Sat, 08 Jun 2013 09:28:43 GMT
Server: Apache/2.2.14 (Ubuntu)
X-Powered-By: PHP/5.3.2-1ubuntu4.18
X-Drupal-Cache: MISS
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified: Sat, 08 Jun 2013 09:28:43 +0000
Cache-Control: public, max-age=300
ETag: "1370683723-0"
Content-Language: en
X-Generator: Drupal 7 (http://drupal.org)
Vary: Cookie,Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8
mcdruid@ubuntu-lucid:~> drush @d7sand ev '$cached_page = cache_get("http://d7sandbox.lucid/", "cache_page"); unset($cached_page->data); if (is_numeric($cached_page->created)) { $cached_page->created_h = date('r', $cached_page->created); $cached_page->expire_h = date('r', $cached_page->expire); } else { $cached_page = "no cache entry\n"; } print_r($cached_page); ';
stdClass Object
(
[cid] => http://d7sandbox.lucid/
[created] => 1370683725
[headers] =>
[flushes] => 0
[expire] => 1373275722
[created_h] => Sat, 08 Jun 2013 10:28:45 +0100
[expire_h] => Mon, 08 Jul 2013 10:28:42 +0100
)
mcdruid@ubuntu-lucid:~> drush @d7sand cc all
'all' cache was cleared in d7sand [success]
mcdruid@ubuntu-lucid:~> drush @d7sand ev '$cached_page = cache_get("http://d7sandbox.lucid/", "cache_page"); unset($cached_page->data); if (is_numeric($cached_page->created)) { $cached_page->created_h = date('r', $cached_page->created); $cached_page->expire_h = date('r', $cached_page->expire); } else { $cached_page = "no cache entry\n"; } print_r($cached_page); ';
no cache entry
mcdruid@ubuntu-lucid:~>
Result: cc all removes cache_page entries
3) cache_page in memcache with authcache enabled
config in settings.php
$conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';
$conf['cache_backends'][] = 'sites/all/modules/authcache/authcache.inc';
$conf['cache_class_cache_page'] = 'MemCacheDrupal';
$conf['cache_class_cache_form'] = 'DrupalDatabaseCache';
$conf['cache_default_class'] = 'MemCacheDrupal';
Test: (n.b. I had to flush memcache manually in order to start with an empty cache_page)
mcdruid@ubuntu-lucid:~> drush @d7sand cc all
'all' cache was cleared in d7sand [success]
mcdruid@ubuntu-lucid:~> drush @d7sand ev '$cached_page = cache_get("http://d7sandbox.lucid/", "cache_page"); unset($cached_page->data); if (is_numeric($cached_page->created)) { $cached_page->created_h = date('r', $cached_page->created); $cached_page->expire_h = date('r', $cached_page->expire); } else { $cached_page = "no cache entry\n"; } print_r($cached_page); ';
stdClass Object
(
[cid] => http://d7sandbox.lucid/
[created] => 1370683725
[headers] =>
[flushes] => 0
[expire] => 1373275722
[created_h] => Sat, 08 Jun 2013 10:28:45 +0100
[expire_h] => Mon, 08 Jul 2013 10:28:42 +0100
)
mcdruid@ubuntu-lucid:~> echo "flush_all" | nc localhost 11211
OK
mcdruid@ubuntu-lucid:~> drush @d7sand ev '$cached_page = cache_get("http://d7sandbox.lucid/", "cache_page"); unset($cached_page->data); if (is_numeric($cached_page->created)) { $cached_page->created_h = date('r', $cached_page->created); $cached_page->expire_h = date('r', $cached_page->expire); } else { $cached_page = "no cache entry\n"; } print_r($cached_page); ';
no cache entry
mcdruid@ubuntu-lucid:~> curl -sIXGET http://d7sandbox.lucid/
HTTP/1.1 200 OK
Date: Sat, 08 Jun 2013 10:37:53 GMT
Server: Apache/2.2.14 (Ubuntu)
X-Powered-By: PHP/5.3.2-1ubuntu4.18
X-Drupal-Cache: MISS
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified: Sat, 08 Jun 2013 10:37:53 +0000
Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0
ETag: "1370687873"
Content-Language: en
X-Generator: Drupal 7 (http://drupal.org)
Vary: Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8
mcdruid@ubuntu-lucid:~> drush @d7sand ev '$cached_page = cache_get("http://d7sandbox.lucid/", "cache_page"); unset($cached_page->data); if (is_numeric($cached_page->created)) { $cached_page->created_h = date('r', $cached_page->created); $cached_page->expire_h = date('r', $cached_page->expire); } else { $cached_page = "no cache entry\n"; } print_r($cached_page); ';
stdClass Object
(
[cid] => http://d7sandbox.lucid/
[created] => 1370687876
[headers] =>
[flushes] => 0
[expire] => 1373279872
[created_h] => Sat, 08 Jun 2013 11:37:56 +0100
[expire_h] => Mon, 08 Jul 2013 11:37:52 +0100
)
mcdruid@ubuntu-lucid:~> drush @d7sand cc all
'all' cache was cleared in d7sand [success]
mcdruid@ubuntu-lucid:~> drush @d7sand ev '$cached_page = cache_get("http://d7sandbox.lucid/", "cache_page"); unset($cached_page->data); if (is_numeric($cached_page->created)) { $cached_page->created_h = date('r', $cached_page->created); $cached_page->expire_h = date('r', $cached_page->expire); } else { $cached_page = "no cache entry\n"; } print_r($cached_page); ';
stdClass Object
(
[cid] => http://d7sandbox.lucid/
[created] => 1370687876
[headers] =>
[flushes] => 0
[expire] => 1373279872
[created_h] => Sat, 08 Jun 2013 11:37:56 +0100
[expire_h] => Mon, 08 Jul 2013 11:37:52 +0100
)
Result: cc all DOES NOT remove cache_page entries
4) cache_page in the db with memcache and authcache enabled
config in settings.php
$conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';
$conf['cache_backends'][] = 'sites/all/modules/authcache/authcache.inc';
$conf['cache_class_cache_page'] = 'DrupalDatabaseCache';
$conf['cache_class_cache_form'] = 'DrupalDatabaseCache';
$conf['cache_default_class'] = 'MemCacheDrupal';
Test:
mcdruid@ubuntu-lucid:~> drush @d7sand cc all
'all' cache was cleared in d7sand [success]
mcdruid@ubuntu-lucid:~> drush @d7sand ev '$cached_page = cache_get("http://d7sandbox.lucid/", "cache_page"); unset($cached_page->data); if (is_numeric($cached_page->created)) { $cached_page->created_h = date('r', $cached_page->created); $cached_page->expire_h = date('r', $cached_page->expire); } else { $cached_page = "no cache entry\n"; } print_r($cached_page); ';
no cache entry
mcdruid@ubuntu-lucid:~> curl -sIXGET http://d7sandbox.lucid/
HTTP/1.1 200 OK
Date: Sat, 08 Jun 2013 10:59:44 GMT
Server: Apache/2.2.14 (Ubuntu)
X-Powered-By: PHP/5.3.2-1ubuntu4.18
X-Drupal-Cache: MISS
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified: Sat, 08 Jun 2013 10:59:44 +0000
Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0
ETag: "1370689184"
Content-Language: en
X-Generator: Drupal 7 (http://drupal.org)
Vary: Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8
mcdruid@ubuntu-lucid:~> drush @d7sand ev '$cached_page = cache_get("http://d7sandbox.lucid/", "cache_page"); unset($cached_page->data); if (is_numeric($cached_page->created)) { $cached_page->created_h = date('r', $cached_page->created); $cached_page->expire_h = date('r', $cached_page->expire); } else { $cached_page = "no cache entry\n"; } print_r($cached_page); ';
stdClass Object
(
[cid] => http://d7sandbox.lucid/
[created] => 1370689184
[expire] => -1
[serialized] => 1
[created_h] => Sat, 08 Jun 2013 11:59:44 +0100
[expire_h] => Thu, 01 Jan 1970 00:59:59 +0100
)
mcdruid@ubuntu-lucid:~> drush @d7sand cc all
'all' cache was cleared in d7sand [success]
mcdruid@ubuntu-lucid:~> drush @d7sand ev '$cached_page = cache_get("http://d7sandbox.lucid/", "cache_page"); unset($cached_page->data); if (is_numeric($cached_page->created)) { $cached_page->created_h = date('r', $cached_page->created); $cached_page->expire_h = date('r', $cached_page->expire); } else { $cached_page = "no cache entry\n"; } print_r($cached_page); ';
no cache entry
Result: cc all removes cache_page entries
Comment | File | Size | Author |
---|---|---|---|
#4 | 2015197-authcache_check_for_drush.patch | 568 bytes | mcdruid |
Comments
Comment #1
mcdruidThis may or may not be related to #1851126: Flushing cache is not clearing the cache?
Comment #1.0
mcdruidexplanation of manual memcache flush
Comment #2
znerol CreditAttribution: znerol commentedThanks for the report. Would you please check the following things:
1. Consistency of configuration
In authcache < 1.4 it easily happened that configuration values were different at the point in time when a page was saved to the cache and when a entry was retrieved from the cache respectively. This may lead to misbehavior which is difficult to detect and reproduce (see e.g. #1966182: Site displays gibberish when authcache is enabled). Therefore please make sure that you force all cache related configuration (including config for memcache) in
settings.php
. A quick grep through the memcache module revealed the following candidates:Also if your
settings.php
file does not reside undersites/default
but in e.g.sites/mysite.com
then make sure thatdrush
picks up the correct configuration by supplying--uri=http://mysite.com
.2. Cache clearing strategies
Please try the following cache clearing strategies and report back whether the results differ:
drush ev "drupal_flush_all_caches();"
This is essentially what the cache clear button from the performence settings does.
drush ev "cache_clear_all(NULL, "cache_page");
This is what cron does
Comment #3
znerol CreditAttribution: znerol commentedComment #4
mcdruidI've tracked this down to a problem with the way that drupal gets bootstrapped via drush with the authcache cache backend included - within authcache_retrieve_cache_page():
For some reason when this is run via drush, the drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES, FALSE) doesn't seem to successfully load the variables from the database, and this means that the cache_get on cache_page ends up creating an incomplete memcache cache object - with the details of flushes missing:
If we simply comment out that cache_get, the cache object works as expected:
With the cache_get commented out, drush cc all effectively clears entries from the cache_page bin (which was the original problem reported in this issue).
As authcache_retrieve_cache_page() isn't really doing anything useful when Drupal is bootstrapped by drush, I'd suggest that a check is added to abort if drupal_is_cli (patch attached).
With this in place, the original problem appears to be resolved.
As an alternative workaround, you could do the check for drush in settings.php and not add the authcache cache backend - something like this:
This doesn't seem to do any harm as far as I can tell.
Comment #5
znerol CreditAttribution: znerol commentedWow, thanks for your thorough investigation. I've stepped through the code and found that when invoked from
drush
, the call todrupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES, FALSE)
advances the bootstrapping level only by one phase toDRUPAL_BOOTSTRAP_DATABASE
instead of by two phases toDRUPAL_BOOTSTRAP_VARIABLES
. I think this is related to how drush_bootstrap_max works, callingdrupal_bootstrap
repeatedly with the next phase only if possible.I agree that it does not make much sense to attempt do deliver cached pages when run from CLI in the first place. Also the solution you are proposing is almost exactly what's already implemented in 2.x.
Committed and pushed 642fdf4.
Thanks a lot!
Comment #5.0
znerol CreditAttribution: znerol commenteds/page_cache/cache_page/g