Cache not working for NOT logged in user
-
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]
- The topic ‘Cache not working for NOT logged in user’ is closed to new replies.