Support

Account

Home Forums General Issues Why does add_field always clear the cache? Reply To: Why does add_field always clear the cache?

  • I’m not the developer, so I don’t know completely what the logic of the caching is.

    I do know that there is no persistent object caching built into ACF. ACF is using the WP cache, the same cache WP uses for storing post, meta and other values so that it does not do multiple DB calls to get the same value over and over again on a single page load.

    If you have this set up to be persistent, then that’s another topic.

    So here is what’s happening from what I understand
    — Check to see if there is a cached value
    —- Yes – USE IT
    —- NO – Get the value and store in cache

    This is generally the way caching works

    Your code is adding values after the value has been added to the cache. Therefore the next time the value is needed the cached value will be use. Since your value is not in the cache, if the cache is not cleared then your added value will not exist because the already cached value will be used. So the cache needs to be regenerated to include your new value.

    I’m sure that the developer is not regenerating everything every time. There are many different cache keys for different parts of the data and only the things that need to be generated are.

    If you are using a persistent cache added to WP then I would suggest adding you own object cache in your own code so that instead of rebuilding your local fields every time that you can use your own cached value to add the entire local field group in one call.