Open defunctl opened 4 years ago
Hi @defunctl
Thanks for the topic, Elliot here - ACF dev.
A little context about the $acf_stores
global. This array contains references to the various stores used throughout the ACF plugin. For example, there are stores used for "per request caching" such as "fields" and "field-groups", and there are stores that hold registered items such as "block-types".
Each store instance contains a method called reset()
which can be used to reset the data.
It should be completely safe to reset some of the "per request caching" stores, and ACF will continue functioning as per usual, repopulating the uncached data as it goes. Resetting the "registered items" stores would lead to some kind of failure, so be sure to avoid that.
In theory, it should be completely fine to run the following code when you want to simulate a new request and avoid previously cached data:
$stores = array( 'fields', 'field-groups', 'values', 'notices', 'local-fields', 'local-groups' );
foreach( $stores as $store ) {
acf_get_store( $store )->reset();
}
hope that helps.
Hey Elliot,
Thanks for the response, I was able to solve my personal problem by refreshing the values via acf_get_store( 'values' )->reset();
before running any of the queries that use ACF and it seems to work great, e.g. I always get the most up to date data.
I should have responded sooner but I just got finished testing it over the weekend. I was previously resetting all the fields, which of course doesn't make sense :)
Hello,
We use a queue system that runs for a long time processing tasks via WP CLI. Some of those tasks fetch posts and ACF fields. As it's running under a single PHP process, once ACF populates the
$acf_stores
global on first run, any new queries will return only stale data as the process is still in memory.Clearing the store, or field data etc has no way to automatically replenish the store in real time, and results in missing data, e.g.
acf_get_store('fields')->reset();
Unless I missed something, there doesn't seem to be a way to clear the store once it's populated and having it auto replenish with fresh data later during run time.
Would one of these features (or a better idea if you have one) be possible in a future release:
Thanks for the great plugin.