Support

Account

Home Forums Bug Reports Issues with object-cache.php

Solving

Issues with object-cache.php

  • I have spotted a number of issues with the current version (5.6.2) of ACF when object-cache is enable. Object caching officially supported by core and many sites, including WordPress.com use it to scale. However it appears that this plugin has not been tested using object-caching enabled.

    First issue, that none of the fields register in the admin terminal. See screenshot. I got the following error.

    
    Warning: Invalid argument supplied for foreach() in /app/web/wp-content/plugins/advanced-custom-fields-pro/includes/api/api-field-group.php on line 199
    
    Call Stack:
        0.0028     432776   1. {main}() /app/web/wp-admin/post.php:0
        5.0263   32297272   2. include('/app/web/wp-admin/edit-form-advanced.php') /app/web/wp-admin/post.php:173
        5.0554   32421216   3. require_once('/app/web/wp-admin/admin-header.php') /app/web/wp-admin/edit-form-advanced.php:472
        5.0842   32620536   4. do_action() /app/web/wp-admin/admin-header.php:142
        5.0842   32620912   5. WP_Hook->do_action() /app/web/wp-includes/plugin.php:453
        5.0842   32620912   6. WP_Hook->apply_filters() /app/web/wp-includes/class-wp-hook.php:323
        5.0897   32622432   7. acf_input->admin_head() /app/web/wp-includes/class-wp-hook.php:298
        5.0897   32622432   8. do_action() /app/web/wp-content/plugins/advanced-custom-fields-pro/includes/input.php:216
        5.0897   32622808   9. WP_Hook->do_action() /app/web/wp-includes/plugin.php:453
        5.0897   32622808  10. WP_Hook->apply_filters() /app/web/wp-includes/class-wp-hook.php:323
        5.0897   32623936  11. acf_form_post->admin_head() /app/web/wp-includes/class-wp-hook.php:298
        5.0897   32623936  12. acf_get_field_groups() /app/web/wp-content/plugins/advanced-custom-fields-pro/includes/forms/form-post.php:166
    

    This is because when object caching is enable, the wp_get_cache returns value by default. You want to change it the following lines.

    in api/api-field-group.php

    From

    
    if( acf_isset_cache($cache_key) ) {
    
    		$post_ids = acf_get_cache($cache_key);
    
    	// query DB for child ids
    	}
    

    to

    
    if( acf_isset_cache($cache_key) && acf_get_cache($cache_key)) {
    
    		$post_ids = acf_get_cache($cache_key);
    
    	// query DB for child ids
    	}
    

    There is a similar issue with the text field as well, that returns false. in fields/text.php I added the following lines to fix the issue.
    Line 113

    
       if ( $atts['value'] === false ) {
           $atts['value'] = "";
       }
    
  • Please submit bug reports of this nature by opening a new support ticket here https://support.advancedcustomfields.com/new-ticket/

  • What’s the official status on object-cache with ACF? I see treads dating back from 2012 people systematically asking for embracing the feature. it seems like it was implemented at some point but never really working properly.

    Was this OP issue ever fixed, what’s the general status?
    I’d love to be able to use WP-Redis.

    • wpmark

    • June 21, 2018 at 6:36 am

    I too am seeing this problem when I have an object cache turned on. @spaced_monkey‘s code suggestion removes the issue.

    Any word on whether / when a fix for this will be sorted please?

    • Elliot

    • June 27, 2018 at 10:21 am

    Hi guys

    Object caching is definitely something that got forgotten about in the last few years, my bad.

    I’m currently wrapping up work on version 5.7, and think this is a good time to focus on caching. The first step is for me to replicate the issue. Can someone provide some simple info about setting up caching on a local site?

    Is it as simple as installing a plugin? Or do I need to configure settings in my local environment. For reference, I use a combination of MampPRO and Local by flywheel for local testing.

    • wpmark

    • June 27, 2018 at 9:48 pm

    I thought, but not certain as I don’t use MAMP Pro anymore that it was a setting you could choose to switch on, just like you can switch between different PHP versions.

    • Elliot

    • June 29, 2018 at 9:13 am

    Hi @wpmark

    Thanks for the reply.
    I’m not seeing any obvious settings in MAMP PRO. I’ll jump online and find some tutorials for setting up local object caching. If you know of any good ones, please let me know.

    • xmginc

    • September 18, 2018 at 8:15 am

    I’m curious if information from this site has helped anyone with Object Cache and ACF?

    https://support.pagely.com/hc/en-us/articles/115002105112-Advanced-Custom-Fields-Pro-and-Object-Cache-Compatibility

    From their site:

    Problem

    The Advanced Custom Fields plugin disables persistent caching, as shown in the following function on line 30…

    wp_cache_add_non_persistent_groups(‘acf’);

    While using an Object Cache boosts performance for your site, using this plugin with it enabled can cause inconsistencies and unexpected behavior. See more information about this issue here.
    Solution

    If not using the plugin isn’t an option you can attempt to use the redis-cache plugin workaround.

  • Is there any updates on this issue? Our site is with SiteGround and we are getting Warnings about ACF still.

    • Elliot

    • November 17, 2018 at 10:37 am

    @pasadenaweb Thanks for the question. Unfortunately, I have not made any progress with this as all my attention is dedicated to Gutenberg issues at the moment.
    Thanks for your understanding.

  • @elliot I am upset that this hasn’t been handled in over a year. Specially since, I have already done the hard work and even you the exact code you have to change. I am also sad to find that github has not been updated. The version on github is 4.4.2 (https://github.com/elliotcondon/acf/releases).

    Object caching is not an adanced feature anymore. WP Engire, site ground and VIP GO all have object caching out of the box. This means you plugin is broken for some of the biggest hosts in the world for the highest traffic-ed sites.

    I know that you business is in pro version, but I would love it if you follow model similar to yoast, where you have the free version of github, taking feedback and patch from the community and keep pro version paid for in another repo.

    I am on twitter and wordpress slack, just search spacedmonkey and you should find me if you wish to discuss the patch.

    • Elliot

    • November 21, 2018 at 9:44 am

    Hi @spaced_monkey

    Thanks for the reply, and for calling me out on this.

    I agree with you, and am also frustrated that I haven’t solved this yet.
    The good news is that I have been collecting information from a few support tickets on this same subject and have plans to fix this as soon as possible.

    This year has been a big one, and I haven’t been able to tick off all the to-do’s on my list. This issue effects both the free and PRO users, so please don’t think this has anything to do with finances.

    Right now, I am dedicating all my time to Gutenberg related work and trying my hardest in all areas to make sure that WordPress continues to function as a flexible and reliable CMS.

    The issue itself is quite simple. I had made use of the $found parameter in wp_cache_get() as per the documentation (https://codex.wordpress.org/Function_Reference/wp_cache_get), but it turns out that some object caching does not respect/modify this parameter.

    I’m happy to simplify my code and will do so after the Guten-dust settles.
    Your help is and will be greatly appreciated. If not already, can you please open up a support ticket here (https://www.advancedcustomfields.com/contact/) and ask for me personally (Elliot) to discuss this object caching issue with? This community forum is a great way for devs to communicate, but is not my primary area to work on bugs.

    Thanks
    E

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.