Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Contributor Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    https://ww.wp.xz.cn/plugins/autoptimize/ ?

    I’d guess you’re having a race condition, where Autoptimize cache is caching around the same time as Varnish.

    Hiya Mika;
    Seems the question is rather; does Varnish HTTP purge have a method AO could invoke to purge Varnish’ cache when AO’s is deleted (to avoid having HTML in Varnish which references autoptimized CSS/ JS which does not exist any more)?

    frank

    Or, alternatively as some page caching plugins do, could Varnish HTTP purge hook into an Autoptimize action (autoptimize_action_cachepurged) to delete it’s own page cache.

    somehow I’d like that even better 😉

    frank

    Plugin Contributor Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    You can edit your posts for an hour from making it, to prevent a double post, Frank.

    And I understood the question, I wanted to be sure I was looking at the right plugin 🙂 There are 45k plugins. I try not to assume the one I think they mean is the right one.

    That’s a funny question, y’know… Because I’m not sure what the best order here is, in part because I’m not 100% up to speed on how your plugin (if that IS the right one 😉 ) works. Looking at how you coded around WP Super Cache, that may be the route we have to do.

    I already have a filter for varnish_http_purge_events:

    protected function getRegisterEvents() {
    
    		// Define registered purge events
    		$actions = array(
    			'save_post',            // Save a post
    			'deleted_post',         // Delete a post
    			'trashed_post',         // Empty Trashed post
    			'edit_post',            // Edit a post - includes leaving comments
    			'delete_attachment',    // Delete an attachment - includes re-uploading
    			'switch_theme',         // Change theme
    		);
    
    		// send back the actions array, filtered
    		// @param array $actions the actions that trigger the purge event
    		return apply_filters( 'varnish_http_purge_events', $actions );
    	}

    That would work for individual posts.

    Though it sounds like you need to flush the WHOLE cache and not just the ones for the post? I’m not 100% sure ‘when’ this situation is popping up. I’m guessing that what’s going on is the OP is flushing the Autoptimize cache after making ‘some change’ to the theme, and then has to flush the whole Varnish cache.

    I don’t have a way to externally trigger the whole Varnish cache. It’s intentional that it has to be a conscious manual action, since you really should RARELY be doing anything that requires it. The common situations are ‘adding new plugins’ and ‘changing themes manually’ which really should be rare occurrences.

    The use case indeed is purging the entire cache of both Autoptimize and Varnish, so a pity there’s no such action in Varnish HTTP Purge.

    But wouldn’t switch_theme in your array of registered purge events have to result in the flushing of the entire Varnish cache?

    frank

    Plugin Contributor Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    You don’t have to sign your posts 🙂 Frank you should read https://codex.ww.wp.xz.cn/Forum_Welcome

    switch_theme IS in there for flushing cache already (I thought it was removed, but I see it in my 3.9 alpha code …)

    That said, I know your usecase is purging both, but that’s not actually a full usecase. WHY do you need to flush the whole Autoptimize cache? What changes are being made? How often do people really do this? The OP made it sound like it was a regular occurrence which a full cache flush really should never be.

    Using any caching while actively developing your site’s design is a recipe for pain 🙂

    Plugin Contributor Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    Hours later, I see why it’s not happening in certain cases. 3.9 will address this and add in a filter so people can add events that trigger a full flush.

    You don’t have to sign your posts 🙂

    I’m stubbornly formal in a somewhat informal manner 😉

    WHY do you need to flush the whole Autoptimize cache? What changes are being made? How often do people really do this? The OP made it sound like it was a regular occurrence which a full cache flush really should never be.

    well, purging AO’s cache for one page only is not possible, as the same autoptimized file (CSS or JS) can very well (and ideally is) used accross multiple pages/ posts/ archives/ … hence the a cache purge for AO is always a full one. typically users would do that when something changes in the CSS/ JS, be it when switching themes or installing (or removing) plugins.

    Using any caching while actively developing your site’s design is a recipe for pain 🙂

    sure, but a WordPress install is always in flux with theme or plugin updates (or installs or removals).

    Hours later, I see why it’s not happening in certain cases. 3.9 will address this and add in a filter so people can add events that trigger a full flush.

    great!! 🙂

    kind regards,
    frank

    Plugin Contributor Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    sure, but a WordPress install is always in flux with theme or plugin updates (or installs or removals).

    Okay that’s a hella good point. I stopped using Google PageSpeed because flushing the compressed CSS/JS was an exercise in swearing.

    I’m tempted to put in an auto-flush when you activate/deactivate a plugin, except that’s not always when the need might occur… Hrm.

    I can add in autoptimize_action_cachepurged though! No real harm in that.

    If you want to test it with 3.9, you can download the zip here – https://github.com/Ipstenu/varnish-http-purge/archive/REL_3.9.zip

    I’ve tested it on a live site and it works as I think it should.

    Can’t test now (on holiday), but that should indeed work perfectly.

    ac1643, can you test?

    sunny greetings from the south of France 😉
    frank

    Thread Starter ac1643

    (@ac1643)

    Hi Mika and Frank, thanks for collaborating on this. I am also away right now but should be able to test by the start of next week.

    Many thanks

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Working with Autoptimize’ is closed to new replies.