Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author George Notaras

    (@gnotaras)

    Hello,

    I’ve been thinking about this lately as well and have started considering adding an extra setting for logged in users. Your feedback and suggestions are welcome.

    In the meantime, what you need can be achieved by adding the following code in the functions.php file of the theme or in a private plugin with customizations:

    function addh_no_cache_for_logged_in_users( $options ) {
        if ( is_user_logged_in() ) {
            $options['cache_max_age_seconds'] = 0;
        }
        return $options;
    }
    add_filter( 'addh_options', 'addh_no_cache_for_logged_in_users', 10, 1 );

    Hope this helps.

    George

    Thread Starter bawarka

    (@bawarka)

    Thanks fot help.

    I works… sometimes… but this is progress. Not every page refresh is not cached but aroung 33-40% of refresh is.

    So i`m waiting for this extra setting for logged in users.

    Plugin Author George Notaras

    (@gnotaras)

    Actually, it should work all times. How do you check the headers?

    Plugin Author George Notaras

    (@gnotaras)

    I checked the HTTP headers with a Firefox addon called ‘Live HTTP Headers’ and also tried on the command line with curl, after copying my cookies from the ‘Live HTTP Headers’ output.

    The response after enabling the code I posted earlier:

    ~]$ curl -I -L \
        -H "Accept-Encoding: gzip,deflate" \
        -H "Cookie: wordpress_test_cookie=WP+Cookie+check; wordpress_logged_in_ddabb3a971a9.....blahblah" \
        http://wordpress.example.net/2013/11/25/full-post-example/
    HTTP/1.1 200 OK
    Date: Wed, 07 Jan 2015 23:08:05 GMT
    Server: Apache
    X-Powered-By: PHP/5.4.30
    X-Pingback: http://wordpress.example.net/xmlrpc.php
    Pragma: no-cache
    X-UA-Compatible: IE=edge,chrome=1
    Cleartype: on
    Link: <http://wordpress.example.net/?p=1877>; rel=shortlink
    ETag: "91c6daffe60356f55e9b91e864597bf5aa776ee2"
    Last-Modified: Wed, 07 Jan 2015 03:52:58 GMT
    Expires: Wed, 07 Jan 2015 23:08:05 GMT
    Cache-Control: no-cache, must-revalidate, max-age=0
    Vary: Accept-Encoding
    Content-Encoding: gzip
    Connection: close
    Content-Type: text/html; charset=UTF-8

    The response without the code.

    ~]$ curl -I -L \
        -H "Accept-Encoding: gzip,deflate" \
        -H "Cookie: wordpress_test_cookie=WP+Cookie+check; wordpress_logged_in_ddabb3a971a9.....blahblah" \
        http://wordpress.example.net/2013/11/25/full-post-example/
    HTTP/1.1 200 OK
    Date: Wed, 07 Jan 2015 23:08:25 GMT
    Server: Apache
    X-Powered-By: PHP/5.4.30
    X-Pingback: http://wordpress.example.net/xmlrpc.php
    Pragma: no-cache
    X-UA-Compatible: IE=edge,chrome=1
    Cleartype: on
    Link: <http://wordpress.example.net/?p=1877>; rel=shortlink
    ETag: "91c6daffe60356f55e9b91e864597bf5aa776ee2"
    Last-Modified: Wed, 07 Jan 2015 03:52:58 GMT
    Expires: Fri, 09 Jan 2015 23:08:25 GMT
    Cache-Control: public, max-age=172800
    Vary: Accept-Encoding
    Content-Encoding: gzip
    Connection: close
    Content-Type: text/html; charset=UTF-8

    I get consistent and expected results every time I check according to whether the code is enabled or not.

    A problem I noticed is that WordPress always sends a Pragma: no-cache header. I’ll need to investigate this further.

    Looking forward to your feedback.

    George

    Plugin Author George Notaras

    (@gnotaras)

    Released 1.2.0 which has the new option cache_max_age_seconds_for_authenticated_users set to 0 seconds.

    Also, the issue with the Pragma header has been fixed. That header was sent by WordPress with a value no-cache. It’s a HTTP 1.0 thing, so most caches never take it into account. But you never know. So, this is now fixed as well.

    In my tests I get expected results. Feel free to contact me for any issues you notice.

    Also, if you like this plugin, I’d appreciate adding a review.

    Kind Regards,
    George

    Plugin Author George Notaras

    (@gnotaras)

    Just a quick note. Add-Headers only affects dynamic content that is generated by WordPress. Any cache related headers in HTTP responses of other files have not been set by this plugin, but by the web server.

    George

    Plugin Author George Notaras

    (@gnotaras)

    Also, Add-Headers should not be used together with caching plugins for WordPress, as these plugins create static versions of the content, which is then directly served by the web server instead of the actual dynamic content. In those cases, Add-Headers cannot affect the response headers as they are generated by the web server directly.

    George

    Plugin Author George Notaras

    (@gnotaras)

    Hello. Have you done any testing? Do you get expected results with 1.2.0?

    Your feedback is welcome and appreciated.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘how to set "no-cache" only to logged in people?’ is closed to new replies.