Problem/Motivation
On high traffic sites, we need more control over when nodes get flushed when comments are updated or recommended (voted). It may be detrimental to flush a node from Varnish whenever a comment is posted, especially if comment activity for any particular node is very high. We also don't want to flush the node if the comments appear on a separate page. Same goes for the votingapi.
Proposed resolution
Allow other developers to write their own flushing logic for comments and for the votingapi. This means disabling those hooks. In expire_admin_settings_form(), I'm recommending:
$form['extra'] = array(
'#type' => 'fieldset',
'#title' => t('Optional expiration logic'),
);
$form['extra']['expire_flush_comments'] = array(
'#type' => 'checkbox',
'#title' => t('Expire node when comment is modified'),
'#default_value' => variable_get('expire_flush_comments', EXPIRE_FLUSH_COMMENTS),
'#description' => t('When a comment is modified, flush the node attached to the comment.'),
);
$form['extra']['expire_flush_voting'] = array(
'#type' => 'checkbox',
'#title' => t('Attach expiration logic to voting api'),
'#default_value' => variable_get('expire_flush_voting', EXPIRE_FLUSH_VOTING),
'#description' => t('Flush nodes when voting api events occur.'),
);
In _expire_votingapi():
// Return if admin wants to disable this module's votingapi hooks.
if (variable_get('expire_flush_voting', EXPIRE_FLUSH_VOTING) === FALSE) {
return;
}
In expire_comment():
// Return if admin wants to disable this module's hook_comment().
if (variable_get('expire_flush_comments', EXPIRE_FLUSH_COMMENTS) === FALSE) {
return;
}
And at the top of expire.module:
define('EXPIRE_FLUSH_COMMENTS', TRUE);
define('EXPIRE_FLUSH_VOTING', TRUE);
Let me know what you think. We can't use this module unless we can write our own hook_comment to include custom flushing logic (for example, only flush Varnish if the comments appear on the same page as a node and it's been more than 5 minutes since the last comment).
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | expire-expiration_logic_optional-d7-1299358-8.patch | 15.69 KB | jaydub |
| #6 | 1299358-expiration_configuration-d7.patch | 16.55 KB | jaydub |
| #6 | 1299358-expire-optional-expiration-d6.patch | 11.52 KB | jaydub |
| #3 | 1299358-expire-optional-expiration.patch | 7.12 KB | msonnabaum |
Comments
Comment #1
jaydub commentedI wrote a patch to configure node types to exclude from expiration here #1363218: Allow node types to be excluded from automatic expiration. It is only processed inside the hook_nodeapi call so it would not be effective for the forcing comments and/or votingapi expirations actions from occurring but if I moved the exclude node type check to the expire_node() function then it would be used by the comments and votingapi expirations. Would this be enough to support what you are asking for?
Comment #2
djbobbydrake commentedjaydub, we would still need the ability to prevent flushing on comments and votingapi actions. Our site allows anonymous users to recommend articles and comments. If we are purging cache whenever someone hits the recommend button, that can potentially take our site down.
Comment #3
msonnabaum commentedWhile the current expiration logic is thorough, it is not going to work for all sites. It would be best if all of it was optional so that you can implement only what you need or specify your own logic with rules.
The attached patch is against the D7 branch which incorporates the changes described above as well as new options for node and user expiration. It has the added benefit of making optional the parts of this module that are currently very broken in D7 so that this branch can at least be used with rules.
Comment #4
djbobbydrake commented+1 on the patch in #3
Comment #5
jaydub commentedI'm working on a patch for d6 for this and noticed that the logic for the test against the variables for whether or not to expire comments/nodes/users is backwards:
The variable_get() call here in the hook_comment_*, hook_nodeapi_* and hook_user_* implementations should be of the form:
+ if (empty($comment->nid) || !variable_get('expire_flush_comments', EXPIRE_FLUSH_COMMENTS)) {
since this is the test for whether or not to return early in the function w/o processing any expirations. Obviously if variable_get() is TRUE as it would be if you wanted to expire comments then the current patch would actually never process expirations.
Comment #6
jaydub commentedOk I've got a big patch for d6 and d7 that incorporates the request for an option to enable/disable expiration of nodes, comments, users or votingAPI events. I've folded in the patch from #1363218: Allow node types to be excluded from automatic expiration as well so that you can also exclude certain node types from expiration which in the end should allow for the best of all worlds configurability.
The UI gets a little busy in this case so I threw in a quickie JS to show/hide the options for nodes, comments, etc depending on whether the main option to enable/disable expiration of nodes, comments, etc is checked.
Comment #7
jaydub commentedComment #8
jaydub commentedUpdated patch for drupal 7 branch now that I'm back to testing Expire/Purge with Varnish.
Comment #9
spleshkaPlease, check out new 7.x-2.x branch. There are a lot of options for cache expiration. Moreover, you may set your own expiration rules using Rules + Cache expiration modules together.
Comment #10
spleshkaForgot to change version number.
Comment #11.0
(not verified) commentedfixing formatting in code suggestions