• Hi,
    I have a specific issue tested on a site I was working on (and disabling the object cache the issue disappears). By steps:

    – entering a plugin admin page, it loads a set of options using get_option(…) which returns an array (the set of options – an associative array – is serialized by WP)
    – a form with those options is shows
    – the user changes some of those options and saves: the update_option(…) with the new array is called
    – the admin page reloads and starts a series of ajax calls (to the standard wp-admin/admin-ajax) to compute some results using the new set of options and display them
    – the ajax handler, a regular one coded using the WP standard and registered with “wp_ajax_[action]” uses the get_option(…) to retrieve the set of new options

    Note: “wp_ajax_*” is used and not the “wp_ajax_no_priv_*”.

    The ajax handler does not get back the new saved options but the previous one. Dumping them shows actually the old values. Hence the update_option(…) seems to not trigger a cache invalidation.

    Is there something I can do to have the current set of options when retrieved in an ajax context and not the cached one?

    Thak you, Stefano.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @satollo

    Thank you for reaching out and I am happy to assist you with this.
    Can you please check if the option “Enable caching for wp-admin requests” is enabled in Performance>Object Cache, and if so, disable the checkbox, save all settings and purge the cache and let me know if the problem persists?
    Thanks!

    Thread Starter Stefano Lissa

    (@satollo)

    Hi, I forgot to report that isn’t enabled but a quick view of the plugin code (really quick, actually) shows a check on “DOING_AJAX” which seems to bypass the admin check. I could be totally wrong, anyway.

    🙂

    The object cache is set on “disk” method.

    Thank you, Stefano.

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @satollo

    Thank you for yoru feedback.
    IF you check the code:

    if ( $this->_config->get_boolean( 'objectcache.enabled_for_wp_admin' ) ) {
    		$this->_can_cache_dynamic = true;
    	} else {
    		if ( $this->_caching ) {
    			if ( defined( 'WP_ADMIN' ) &&
    				( !defined( 'DOING_AJAX' ) || !DOING_AJAX ) ) {
    				$this->_can_cache_dynamic = false;
    				$this->cache_reject_reason = 'WP_ADMIN defined';

    So yes you are correct that there is a check. The mentioned option helps to make your administrator dashboard faster, especially if you have multiple users working in the WordPress dashboard. The drawback though is that caching wp-admin requests may result in some unexpected behavior such as displaying outdated data, like in your case.

    Like Database Cache, it can be beneficial to use Object Cache if you are on VPS or a dedicated server, get a lot of traffic, and have a lot of comments. Also, if you know that database is the bottleneck of your website performance, then Object Cache (like Database Cache) is beneficial to use. But in this case, it’s recommended to use Opcode, Memcached, or Redis options instead of the Disk caching method.

    Thanks!

    Thread Starter Stefano Lissa

    (@satollo)

    Ok, what can I do to compensate for that behavior during an ajax call? For example, in the ajax handler, if I need to get the very last version of the options (name it “myoption”) with get_option(‘myoption’), should I run a wp_cache_flush()? Or “invalidate” that specific option in some way?

    Thanks, Stefano.

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @satollo

    Thank you for your feedback and your patience.
    I am trying to replicate the problem. Purging the Object Cache should solve the problem in this case, or you can add it to a Non-persistent groups: field in Performance>Object Cache, and exclude it from being cached.

    I hope this helps!

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Object cache and AJAX issue’ is closed to new replies.