• Resolved chabekah

    (@chabekah)


    This may be related to my earlier query – although I am not sure how…

    As mentioned, Docket Cache seemed to work fine. However, I have noticed something strange and my debugging own code debugging has not been able to isolate the issue as yet.

    In short, the plugin will cache large database results and save them to the file system for use in future requests for a logged on user, but for non-logged in users, the data is not persisted to the file system.

    Here is my debugging code:

    if ( ! $result = wp_cache_get($key, TvGuide::FLUSH_GROUP)) {
      error_log(microtime() . ' not in cache (' . $key . ')');
      $result = $wpdb->get_results(
        /** a rather intensive SQL query */
        $wpdb->prepare($sql, $start_time, $end_time, $start_time, $end_time)
      );
    
      if (wp_cache_supports('flush_group')) {
        error_log(microtime() . ' flush_group supported');
        $set_result = wp_cache_set($key, $result, TvGuide::FLUSH_GROUP, WEEK_IN_SECONDS);
        if ($set_result) {
          error_log(microtime() . ' cache set successfully');
          $test_get = wp_cache_get($key, TvGuide::FLUSH_GROUP);
          error_log(microtime() . ' count = ' . count($test_get));
        } else {
          error_log(microtime() . ' cache not set');
        }
      } else {
        error_log(microtime() . ' flush_group not supported');
      }
    } else {
      error_log(microtime() . 'cache hit! (' . $key . ')');
    }
    

    Whether the user is logged in or not, if the cache is empty, then the code reports that flushing by group is supported, and that the cache has now been successfully set (with a test retrieval to prove it).

    However, for a subsequent request to the same page, then it appears the cache is only persisted between requests for logged-in users. I can see this by checking the file system as well. New cache files are only written to wp-content/cache/docket-cache for logged in users. I have only tested it with me as the admin user; I haven’t tested for other user roles.

    I can also see this same behaviour when I switch on logging in docket-cache – although for non-logged in users, other database requests seem to be being cached and saved to the file system. But my one isn’t, and I don’t know why it is behaving this way. I can’t see anything obvious in your dc_save() function that should stop things from being saved for non-logged in users. I also tried running your plugin in “transient mode” (rather than file system mode) and that didn’t seem to make any difference.

    Do you have any suggestions? Otherwise, your plugin seems to work really well and I’d love to use it.

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Nawawi Jamili

    (@nawawijamili)

    Hi there,

    Docket Cache should work for logged-in and logged-out users. Since it is an object caching plugin, It has no conditional rules to exclude it based on the session.

    The only explanation for this, Docket Cache refuses to cache, maybe the object is too big. Please refer here https://docs.docketcache.com/constants#docket_cache_maxsize for more details.

    Thanks.

    Thread Starter chabekah

    (@chabekah)

    Thanks Nawawi for getting back to me so quickly.

    I don’t think it’s a size issue. The object is cached just fine for a logged on user, and whether you are logged on or not doesn’t make any difference to what is in the object I want to cache. However, I checked the object sizes as you suggest. The max size is the default value of 3145728, and my item is 27521 – so it’s well below the limit.

    I don’t experience this behaviour when testing locally, so I’m wondering if WP Engine is doing something to clobber your Nawawi\DocketCache\Filesystem() function… but I really don’t know why that would happen for logged in users only.

    Unless you have any other suggestions, I am going to have to give up on your plugin and use the WP transient API instead. Or maybe find another plugin similar to yours. Which would be a shame because I really like the way yours (almost!) works. Many thanks, Charles

    Plugin Author Nawawi Jamili

    (@nawawijamili)

    Hi,

    I’m sorry, that’s all I can suggest.

    Thanks.

    Thread Starter chabekah

    (@chabekah)

    OK fair enough. I’ll switch to something else… Thanks for your help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Cache not working for NOT logged in user’ is closed to new replies.