Tagged: object cache, redis
-
AuthorPosts
-
June 8, 2020 at 9:14 am #1220395
Hi there,
we faced the issue with the exploding “dynamic_avia” folder and found your toggle in the “Performance -> Unique timestamp of merged files” section. We have this issue only after activating an external Object Cache using REDIS.
If REDIS is enabled, then many CSS files are generated as well as newly activated Enfold module styles are missing in the newly generated CSS.In the enfold settings you write:
To fix this Enfold adds an additional unique timestamp (since 4.7). Some server configurations cache internal WP data and therefore return wrong information about the existence of a compressed file – resulting in generating a new file again on every pageload and a rapidly growing folder ../wp-content/uploads/dynamic_avia.
We checked your source code but could not find any usage of the WordPress cache functions. We were looking for a way to exclude your entities from the cache. But as you do not use the WordPress cache functions, there is no way to exclude it.
Can you share some more technical insights about the source of the issue that lots of merged css is being generated? What is the “internal WP Data” being cached? I only saw transients and direct DB calls. Which both shouldn’t be an issue, if handled correctly.
If you could provide us with some more details, we would like to find a solution here.
Thanks and best regads,
Jan
June 10, 2020 at 3:10 pm #1221226Hey Jan,
After generating the merged files Enfold writes info about that to WP options table.
If you check config-templatebuilder\avia-template-builder\php\asset-manager.class.php line 142:
$generated_files = get_option( $this->db_prefix . $file_group_name );
And this is the problem with some server configurations not returning the info we stored before in line 270:
update_option( $this->db_prefix . $file_group_name, $generated_files );
Therefore Enfold creates the merged files again and again.
Did you try to select “Disable adding unique timestamp” ? It still may take some time till the correct WP database entry is returned – but as it is always the same filename generated – this will result in overwriting the same file.
Best regards,
GünterJune 10, 2020 at 5:38 pm #1221279Jup, we tried that. Worked well.
But using WP-Redis also led to problems with the dynamic merging of only required styles. Enfold wasn’t able to reliable recognize new modules being activated or used. And thus their styles were missing in the avia-merged css.Sounds to me that both issues are very closely related. As far as I know, the status of the used modules is also stored as options, correct?
But still, as they are default WP Options, therer shouldn’t be an issue. For example, WP-Redis only caches transients as well as the WordPress Object Cache => https://codex.wordpress.org/Class_Reference/WP_Object_Cache
We didn’t see any other issue with options being wrongly read.If you have any more debug information, I would highly appreciate it. If not, we will have to do some debugging with activated WP-Redis.
Thanks and best regards,
Jan
June 11, 2020 at 12:44 pm #1221647Hi,
Yes, module status is saved in options table and/or post meta table – so it is related.
As code is working correctly in most environments and on dev local host servers it must be a problem that standard WP function like get_option is returning the wrong value.
It seems that get_option is returning a cached version of the db option value and not the updated. A possible reason could be that the merged files are generated within a frontend call.
Best regards,
GünterJune 11, 2020 at 2:12 pm #1221695Hey Günter,
you are absolutely correct. get_option uses wp_cache_get under the hood:
wp_cache_get( $option, 'options' );
Considering the way the wp_options works, there are known issues with race conditions and the
alloptions
fetching / caching: https://github.com/pantheon-systems/wp-redis/issues/221Anyway, this means, that the solution to these problems is to add Object Caching support to your code. In this way, you can control when to update/flush your cache keys without relying on the WordPress options cache being flushed. Only if the object cache does not return anything because it is not used or empty, you could fallback to the default WordPress Options. In this cases there shouldn’t be any problems, because no object caching seems to be in place.
This should be quite a simple task. All you would need to do is using the Object Cache API before falling back to the WP_Options default when working with the css modules and merged files. After having this, you should be safe to remove the “advanced” option to generate single merged files as well.
This should be all you need:
If the
wp_cache_get
command returnsfalse
, fallback toget_option
. Just make sure to add a proper caching group identifier:wp_cache_set( ' avia_merged_file_name ', 'enfold', $cached_file_name);
$file_name = wp_cache_get( ' avia_merged_file_name ', 'enfold'); if ( false === $file_name) { $file_name = get_option( 'avia_merged_file_name'); }
Do you think this is something you could add to the shortterm bugfix releases to add Object Cache compatibility to Enfold?
Thank you very much and best regards,
Jan
June 15, 2020 at 12:34 pm #1222619Hi Jan,
Sorry for the late reply.
Thank you very much for your help. Sounds like this is the solution. And I certainly will have a better eye on WP object cache in future.
I will try to add it to the core for the next release. Please check the changelog.
Have a great day.
Best regards,
GünterJune 15, 2020 at 1:15 pm #1222634Thanks Günter.
You are very welcome and your open mind is highly appreciated :-)
Just as a little pre-warning: We will püem another topic regarding the merged files and file suffix today or tomorrow. While debugging this topic in depth, we were able to confirm, that there are still massive issues with database pollution. Even with no object caching in place. The latter only creates masses of files on the disk.
Best regards,
JanJune 16, 2020 at 12:37 pm #1222988 -
AuthorPosts
- You must be logged in to reply to this topic.