Home › Forums › General Issues › Why does add_field always clear the cache? › Reply To: Why does add_field always clear the cache?
Jumping in here,
Those 2 lines are also causing about 10% of additional load time for me as well. This is only the issue when using Persistent Cache.
I understand why they are deleted, but I agree with Spacedmonkey that it should be a static class variable instead of using the wp_cache or more preferbly ACF checks to see if persistent cache is enabled and doesn’t run those 2 lines.
So the reason for the deletes is if you change the fields then they need to be deleted. Many persistent caches will have some sort of clear all cache method which a developer would know to use when they update the code. Therefore, it is those 2 lines of code should not run when persistent cache is enabled.
So I think the main thing here is ACF needs to determine first if persistent cache is enabled and if so to not run those 2 lines.
There are many ways to check for this, but the easiest that comes to mind would be to check if the file exists (wp-content/object-cache.php)
Spacedmonkey,
For now you can get around this by editing wp-content/object-cache.php
Just edit the “wp_cache_delete” function to only run if the $key and $group don’t match those of the ACF calls.
Just make sure when you update your fields that you delete the object cache.
John and Elliot,
Since many persistent caches with create and delete the wp-content/object-cache.php file on the fly it would make more sense for ACF to run the check. I would recommend that you look into this.
Thanks
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.