WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: WP Super Cache] how-to keep shopping cart dynamic? (33 posts)

  1. RavanH
    Member
    Posted 4 years ago #

    Hi,

    Some available shopping cart plugins like Quick Shop and eShop provide a cart widget and/or have some cart+checkout pages. Is there some documentation on how to make WP Super Cache keep only those parts (widget plus checkout pages) dynamic and still do caching on the rest?

    In the FAQ's I found some info on < !--mfunc .. > and < !--mincl .. > that look useful but I have no idea how to implement these tricks on existing plugin code. Ofcourse it all depends on the particular plugin but is it at all possible? Or should I approach this differently?

    Thanks for any info :)

    http://wordpress.org/extend/plugins/wp-super-cache/

  2. elfin
    Moderator
    Posted 4 years ago #

    Looking through posts for the cache plugin I found this:
    http://wordpress.org/support/topic/256416?replies=3

    Looks like you can specify parts of the blog not to be cached. Just add in the auto generated pages - specifically the cart, checkout, cancelled and thank you for your order pages.

    I don't know about the widget though, sorry.

  3. RavanH
    Member
    Posted 4 years ago #

    Thanks, elfin. Right, excluding the checkout pages and such via their slug name would be the easiest method.

    However, what I am looking for is some way to make the QuickShop and eShop plugins sort of work together with SuperCache and make this exclusion automatic instead of leaving it to individual users to set the exclusion manually.

    Or maybe SuperCache could include the appropriate exclusion rules by default? That would be nice enough :) and a new setting in SuperCache allowing certain widgets to stay dynamic sounds good too! ;)

  4. elfin
    Moderator
    Posted 4 years ago #

    people are free to change pages though, eShop doesn't really care where they are, so long as it knows.

    Hmmm, I did have a quick look at the cache, but didn't see an easy method to add things via a plugin to it's exclude list. I'd prefer via page id, because then I can link to the existing settings within eShop. So if you can find out how, then I can add it without a problem... (I think)

  5. Donncha O Caoimh
    Member
    Posted 4 years ago #

    You could have the plugin set the DONOTCACHEPAGE constant. That will stop the plugin caching them.

    See http://ocaoimh.ie/wp-super-cache-developers/ for more.

  6. elfin
    Moderator
    Posted 4 years ago #

    I'm not familiar with the cache plugin, but is it not possible to add a setting to the edit post/page that would stop that particular page from being cached?

    At what stage is that constant used, can I add it to a function that filters on the content?

  7. RavanH
    Member
    Posted 4 years ago #

    Thanks donncha, for chipping in here. that looks like a promising constant... is DONOTCACHEPAGE only used by supercache or is that a wp-cache constant? I mean, it might serve its purpose well when included in eShop but only if we can be sure it will not affect other situations where SuperCache is not running.

    And along the same line, is there no constant like DONOTCACHEWIDGET ?

    Do the < !--mfunc .. > and < !--mincl .. > tags work when used inside plugin files or only in theme files?

  8. Donncha O Caoimh
    Member
    Posted 4 years ago #

    elfin - that constant is used right at the end of the request so set it at any time before shutdown and the page won't be cached.

    RavanH - no constant for widgets, as the plugin is a full page caching tool!
    Those tags will work anywhere just as long as they're printed to the browser.

  9. RavanH
    Member
    Posted 4 years ago #

    Rich, do you see any possibility to get the constant DONOTCACHEPAGE into eShop? Or do you think a plugin for SuperCache (like done for Bad Behavior and No Adverts for Friends) would be a better approach?

    donncha, what is preferred: a plugin for SuperCache (which means we can be sure the constant is set before anything else?) or just use the constant in the shop plugin?

  10. elfin
    Moderator
    Posted 4 years ago #

    aha - thanks Donncha.

    RavanH if you email me I'll send you a version to test, and I'll work with you until we get it working.

  11. RavanH
    Member
    Posted 4 years ago #

    Donncha, i am still not clear about this method of keeping a function dynamic. trying to get the output of a widget stay dynamic, i converted the widget function to output <! --mfunc .. > and then call a second function where the output is generated. This now looks like this:

    function my_widget($args) {
    	global $blog_id;
    	...
    	echo $before_title.$title.$after_title; ?>
    <!--mfunc eshop_widget_dynamic_output($blog_id) -->
    <?php my_widget_dynamic_output($blog_id) ?>
    <!--/mfunc-->
    <?php
    	echo $after_widget;
    }
    function my_widget_dynamic_output($blog_id){
    	echo 'this is wpmu blog '.$blog_id;
    }

    This seems to work in ON mode on WPMU 2.8.6 except for the fact that the the last line of the page source shows
    <!-- Dynamic page generated in ... seconds. --> and no longer the usual
    <!-- Cached page generated by WP-Super-Cache on ... -->

    Moreover, in HALF ON mode only the first time I load a page with this widget, it shows the correct content. Reloading the page will show content up to the widget and to abort with <! --mfunc--> .

    I have the feeling I am missing the point here. Would you enlighten me a bit more?

  12. Donncha O Caoimh
    Member
    Posted 4 years ago #

    Check your php error log? Anything there?

    You should use the plugin in half-on mode with dynamic mfunc code. I've just noticed a bug in the plugin where the static file is generated even when dynamic code is detected. That'll be fixed in the next release.

    Anyway, the cache file is probably being served before the plugin is loaded. Set $wp_super_cache_late_init to 1 in wp-content/wp-cache-config.php to serve the file after "init" and after plugins are loaded. Does that work?

    The mfunc stuff is legacy code from wp-cache. I've never used it as I never had a use for it. Nobody's ever helped with this portion of code so it's not as mature as other parts of the plugin.

  13. elfin
    Moderator
    Posted 4 years ago #

    a version of eShop has now been released with the relevant cache defines in it. Seems to work according to RavanH.

    Thanks both for your help.

  14. RavanH
    Member
    Posted 4 years ago #

    @donncha
    Sadly, I do not have access to error logs on my shared hosting provider (1&1) so that will not reveal any new info... Can you advise me some debugging/error reporting plugin that will work on WMPU maybe?

    About mfunc : I have the feeling it is supposed to be used in template files only. Where ever it is used, it appears to be resulting in the complete page being served dynamically. Not just the function, which probably makes sense, or does WP-Cache work differently? So when used in a widget function, all pages will likely be served dynamically, defeating the whole point of running SuperCache... Am I correct in that assumption?

    About DONOTCACHEPAGE : does that work both in ON and HALF-ON mode?

  15. Donncha O Caoimh
    Member
    Posted 4 years ago #

    Supercache has very extensive debugging.

    mfunc code just has to be printed to the browser. Doesn't matter where the php that prints it is. Only works in half-on mode. You might need to set the late init variable in wp-cache-config.php (see the config file in the plugin directory, might need to update wp-content/wp-cache-config.php)

    DONOTC.. works in any mode. It stops the page being cached. If a page is cached already then it obviously won't work.

  16. microkid
    Member
    Posted 4 years ago #

    Donncha, another question about the DONOTCACHEPAGE constant;

    Is this meant as a flag for a specific page not to be cached, or for a request? I'm trying to figure out a way to not cache pages for users that are not logged in, but I'm using a custom user system, not the one that comes with WordPress. So I'm trying to tell the plugin not to cache requests for or serve cached pages to users with a certain $_SESSION flag.

    I wrote a small plugin, but it doesn't seem to work:

    function wp_super_cache_dont_cache_for_members() {
    	if( $_SESSION['logged_in'] ) {
    		define( "DONOTCACHEPAGE", true );
    	}
    }
    
    add_action("init", "wp_super_cache_dont_cache_for_members");

    TIA

  17. Donncha O Caoimh
    Member
    Posted 4 years ago #

    That should work. You should try debug the plugin by searching for the constant in wp-cache-phase2.php and using error_log()

  18. microkid
    Member
    Posted 4 years ago #

    Thanks, I'll dive into it this week and let you know what comes out.

  19. pauldmtvu
    Member
    Posted 4 years ago #

    Having a similar problem to RavanH. Where the mincl and mfunc seems to die or when a cached version of a post is served.

    Here's a test post:
    http://deadlydragonsound.com/wp/records-for-sale/6286

    we have modified single.php with the following:

    <!--mclude displaybuylink.inc.php-->
    <?php include_once( ABSPATH .'/../includes/displaybuylink.inc.php' ); ?>
    <!--/mclude-->			
    
    <!-- use this code to display the buy link -->
    <!--mfunc displayBuyLink3($recordID)-->
    <?php displayBuyLink3($recordID); ?>
    <!--/mfunc-->

    it works fine uncached (try the usual throwing in ?asdf123 or some junk at end of URL to see it working -- it will display a red "BUY" button)

    I did the suggestion from Donncha:
    $wp_super_cache_late_init to 1 in wp-content/wp-cache-config.php

    and that at least shows some errors, which indicate to me that the function is cached - I think?

    If I change it back to 0, it just dies at <!--mfunc when I view source.

    WordPress 2.9.1 with WP Super Cache 0.9.9 set to Half-on.

    Thanks in advance for any help!

  20. Donncha O Caoimh
    Member
    Posted 4 years ago #

    Paul - the displayBuyLink3() function isn't defined when the cache is displayed unless you use the late init feature. Cache files are normally displayed really early.

  21. pauldmtvu
    Member
    Posted 4 years ago #

    Thanks as always for the speedy replies Donncha.
    We changed the wp-cache-config.php to have:
    $wp_super_cache_late_init = 1;

    It hasn't helped so far. Is there documentation somewhere on how to use the late_init feature?

    If we can't sort it out, it's not a deal-breaker. We'll try going with javascript or maybe just exclude all pages of this category to be non-cached by excluding the category string... though it sure would be nice to keep some caching on all those posts.

    Thanks again
    Paul

  22. pauldmtvu
    Member
    Posted 4 years ago #


  23. Donncha O Caoimh
    Member
    Posted 4 years ago #

    Paul - the developer docs listed above have docs on the late init feature.

  24. Ivan Ong
    Member
    Posted 4 years ago #

    Is there a way to disable caching for the sidebar and footer?

    I tried adding sidebar.php and footer.php into the "Add here strings (not a filename) that forces a page not to be cached." section but it doesn't work.

  25. saharusa
    Member
    Posted 4 years ago #

    I would like to know that too,
    when I use mfunc, page stop loading when trying to execute php code (at the included file)

  26. Donncha O Caoimh
    Member
    Posted 4 years ago #

    saharusa - you have to enable the "late init" feature. It's in the developer docs.

    pinobolino - that won't work. You need to use the mfunc functions. Read the readme.txt

  27. saharusa
    Member
    Posted 4 years ago #

    Hi donncha,
    It is working with late_init but only if i set:
    $cache_compression = 0;
    if I let in enable (i'm using half on) I get blank page with IE and content encoding error with FF.

    Maybe because gzip already enabled by default on my server ?

  28. Donncha O Caoimh
    Member
    Posted 4 years ago #

    It might be, but the plugin tries very hard to figure out if compression is enabled on the server. I'll try to look at this next week but in the meantime it's probably better to leave compression off :)

  29. saharusa
    Member
    Posted 4 years ago #

    Great, I'm looking forward you test results.

    Just to let you know, I tried with versions 0.9.8, 0.9.9 and dev, got same results with all.

    Also, if you any help, server configuration details, just say so, I'll be happy to help.

  30. Donncha O Caoimh
    Member
    Posted 4 years ago #

    Ok, got this fixed in trunk. Try the development version. That should work better for you!

Topic Closed

This topic has been closed to new replies.

About this Topic