• Resolved Rafa? Ca?ka

    (@rafaucau)


    I want to make the post caches (including AMP) to be preloaded immediately after publishing.
    I’ve tried the Preload Fullpage Cache plugin, but LiteSpeed doesn’t cache its requests.

    So I tried with my own code and the problem is the same. Even though the request is sent, after visiting the given post, the header x-litespeed-cache: miss is returned.

    I experimented with headers, trying for example to set User Agent as LiteSpeed Crawler, but it did not help.
    Any ideas what to do to make it work? I don’t know why LiteSpeed doesn’t cache such requests.

    
    add_action( 'save_post', function ( int $postId, WP_Post $post ) {
    	if ( $post->post_type !== 'post' || $post->post_status !== 'publish' || wp_is_post_revision( $post ) ) {
    		return;
    	}
    
    	$args = [
    		'type'    => 'GET',
    		'headers' => [ 'Accept: image/webp,*/*', 'User-Agent: lscache_runner' ]
    	];
    
    	$permalink = get_permalink( $post );
    
    	$postRequest        = $args;
    	$postRequest['url'] = $permalink;
    
    	$ampRequest        = $args;
    	$ampRequest['url'] = $permalink . 'amp/';
    
    	Requests::request_multiple( [ $postRequest, $ampRequest ] );
    }, 900, 2 );
    
    • This topic was modified 2 years, 9 months ago by Rafa? Ca?ka.
Viewing 14 replies - 1 through 14 (of 14 total)
  • POST requests are not cached by default and must be enabled on server level, but in your case this isn’t possible with POST caching. LScache caches by URL request, so you must request the URL of published post first to get it cached.

    A request can be done in several ways and can also be done with cURL. If you have published a post, WP must be extended to send cURL request in backend of WP. But this is only one of more ways how could it be done.

    Thread Starter Rafa? Ca?ka

    (@rafaucau)

    POST requests are not cached by default

    @serpentdriver But it’s GET request. Request is correct and does what you described.

    • This reply was modified 2 years, 9 months ago by Rafa? Ca?ka.

    It doesn’t matter if request is GET or POST. A new post must be requested first before it can be cached.

    Thread Starter Rafa? Ca?ka

    (@rafaucau)

    @serpentdriver And it is requested. This is exactly what the plugin I mentioned and my code does.

    Send POST and requesting URL of published post at the same time doesn’t work.

    Thread Starter Rafa? Ca?ka

    (@rafaucau)

    I send a GET request to the address of a newly created WordPress post. WHAT DOES NOT WORK is caching this WordPress post

    The plugin I mentioned works with other Full Page Cache systems that work the same way as LiteSpeed. That is, the first visits to the page cache it. For some reason this doesn’t work with LSCache when the request doesn’t come from a real browser.

    The problem is not with these plugins, but with LSCache. I suppose there is some header missing in the request.

    The plugin I mentioned works with other Full Page Cache systems that work the same way as LiteSpeed.

    No, LScache is a webserver based HTTP cache. All others use PHP.

    If the other plugin doesn’t work with LScache the reason for it can be that this plugin doesn’t send a real HTTP request like https://wwww.domain.com. You can verify it if you check access_log. If there are no entries coming from this plugin/your server, then this is the confirmation for it.

    Thread Starter Rafa? Ca?ka

    (@rafaucau)

    No, LScache is a webserver based HTTP cache. All others use PHP.

    My point was that caching of the page is triggered in the same way. By the first visit.

    And yes, I verified the request and all the time I am trying to tell you that it works and is correct. The problem is that LSCache does not cache such request.

    The problem is that LSCache does not cache such request.

    The most plausible reason can only be that requests from this plugin are not real and not complete HTTP requests. LScache has no special requirements for it, but always must be a complete URL like http(s)://(www.)domain.com/whatever(.php) and it doesn’t matter where this request come from, internal or external or whatever device/software is used.

    Thread Starter Rafa? Ca?ka

    (@rafaucau)

    You finally understood what I described in the topic ??

    That’s why I ask what could be missing in the request. See the code I provided at the beginning. If you are not a developer, then let’s wait for someone more technically knowledgeable in LiteSpeed like @qtwrk.

    • This reply was modified 2 years, 9 months ago by Rafa? Ca?ka.
    • This reply was modified 2 years, 9 months ago by Rafa? Ca?ka.
    • This reply was modified 2 years, 9 months ago by Rafa? Ca?ka.
    • This reply was modified 2 years, 9 months ago by Rafa? Ca?ka.

    You finally understood what I described in the topic

    Yes and already since in your topic post. I develop plugins for LScache and LiteSpeed since many years, but don’t know code of WP, so you should wait for plugin support. Maybe he has any idea.

    Plugin Support qtwrk

    (@qtwrk)

    Hi,

    actually I don’t have any idea for instance.

    the request code looks alright to me

    but here are something you can try/check/test:

    1. did you enable guest mode ? if so , your request will hit guest page instead of normal page , so if you check normal page with browser that is not first access, you will see it MISS

    2. can try mimic full chrome header , instead of only send accept and UA

    3. plugin’s debug log and server debug log will always be very helpful to give information what exactly has occured

    4. have you checked the crawler source code ? https://github.com/litespeedtech/lscache_wp/blob/master/src/crawler.cls.php

    best regards,

    From what I understand (from server’s debug log), when we publish a post or when we update an existing post, the request from our code (via add_action) gets executed at first. Only then, LSWS flushes the cache. Let me dig further, by looking into the response headers (of the request that tries to preload the post).

    Plugin Support qtwrk

    (@qtwrk)

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘How to preload cache after publishing a post?’ is closed to new replies.