• Resolved borislavzlatanov

    (@borislavzlatanov)


    We have a page (the My Account page on WooCommerce) which shows all products customers purchased. Memcached is caching that page so customers aren’t able to see their latest products on the page right after purchase.

    Is there a way to clear the Memcached cache every time that page is loaded? Or to clear the cache when a purchase is made or a user is added to a specific group (they are added to a new group upon making a purchase)?

    When we were still on cPanel, we managed to accomplish this by calling a little script that programmatically cleared the Memcached cache. However, after the move over to the new Site Tools system, the script is no longer working – seems like Memcached php functions like memcache_connect() aren’t available to us as php fails with a fatal error saying that function is undefined. Which is strange since the Memcached module for php is installed on the server so that function should be available for us to call and programmatically clear the cache.

    Looking for help on any way of accomplishing this.
    Thanks in advance.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Hristo Pandjarov

    (@hristo-sg)

    SiteGround Representative

    Memcached is a form of Object caching. It stores objects and speeds up the communication between your site and the database.

    Most probably some of your plugins additives to Woo are caching content that must not be cached. You can use the wp function to flush the cache on those pages on each load https://www.ads-software.com/support/topic/error-javascript-combination-disabled/ but that’s far from optimal. I’d recommend getting a dev to look into your particular site and check what exactly is being cached as an object.

    Thread Starter borislavzlatanov

    (@borislavzlatanov)

    I remembered that, of course, SG Optimizer clears the Memcached cache programmatically. So I looked at its code and found it does it this way:

    $memcache = new \Memcached();
    $memcache->addServer( '127.0.0.1', 11211 );
    $memcache->set( 'SGCP_Memcached_Test', 'Test!1', 50 );
    
    if ( 'Test!1' === $memcache->get( 'SGCP_Memcached_Test' ) ) {
    	$memcache->flush();
    	return true;
    }

    So I lifted this code and updated our script that clears the cache when that page is loaded. It works. For some reason the old php functions like memcache_connect() which used to work on cPanel stopped working on Site Tools but the above works. Can’t believe I didn’t think of checking out SG Optimizer’s code before. Super easy.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Clearing Memcached for a specific page’ is closed to new replies.