[wp-trac] [WordPress Trac] #58919: Add a hook to set_cached_mo_files() to allow flexible caching strategies for globbing *.mo files

WordPress Trac noreply at wordpress.org
Wed Jul 26 22:20:38 UTC 2023


#58919: Add a hook to set_cached_mo_files() to allow flexible caching strategies
for globbing *.mo files
-------------------------+------------------------------
 Reporter:  mreishus     |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  I18N         |     Version:
 Severity:  normal       |  Resolution:
 Keywords:               |     Focuses:
-------------------------+------------------------------

Comment (by mreishus):

 Here is an example use of this hook:

 {{{#!php
 function wpcom_get_mo_files_from_path( $mo_files, $path ) {
         // We're only concerned with this one directory.
         if ( ABSPATH . 'wp-content/languages/plugins' !== $path ) {
                 return null;
         }

         $cache_group = 'lang-files';
         $cache_key   = 'mo_files_' . md5( $path );
         $cached      = wp_cache_get( $cache_key, $cache_group );

         if ( false !== $cached ) {
                 return $cached;
         }

         $mo_files = glob( $path . '/*.mo' );
         wp_cache_set( $cache_key, $mo_files, $cache_group, 300 );
         return $mo_files;
 }

 add_filter( 'get_mo_files_from_path', 'wpcom_get_mo_files_from_path', 10,
 2 );

 }}}

 I didn't include it because it has no invalidation, and it assumes a
 persistent cache is set up. However, I thought it might be useful to show
 a potential way the hook could be used.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58919#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list