@@ -16,6 +16,7 @@ class Optml_Settings {
16
16
const FILTER_TYPE_LAZYLOAD = 'lazyload ' ;
17
17
const FILTER_TYPE_OPTIMIZE = 'optimize ' ;
18
18
const OPTML_USER_EMAIL = 'optml_user_email ' ;
19
+ const INDIVIDUAL_CACHE_TOKENS_KEY = '_optml_cache_tokens_individual ' ;
19
20
/**
20
21
* Holds an array of possible settings to alter via wp cli or wp-config constants.
21
22
*
@@ -744,15 +745,16 @@ public function clear_cache( $type = '' ) {
744
745
$ token = $ this ->get ( 'cache_buster ' );
745
746
$ token_images = $ this ->get ( 'cache_buster_images ' );
746
747
748
+ // here is an individual cache tokens
749
+ $ individual = get_transient ( self ::INDIVIDUAL_CACHE_TOKENS_KEY ) ?: [];
747
750
if ( ( empty ( $ type ) || $ type === 'images ' ) ) {
748
751
if ( ! empty ( $ token_images ) ) {
749
752
$ token = $ token_images ;
750
753
}
751
754
} elseif ( $ type === 'assets ' ) {
752
755
$ token = $ this ->get ( 'cache_buster_assets ' );
753
756
} else {
754
- // here is an individual clear cache based on filename.
755
- $ token = get_transient ( '_file_ ' . crc32 ( $ type ) ) ?: '' ;
757
+ $ token = $ individual [ crc32 ( $ type ) ] ?? $ token_images ?: $ token ;
756
758
}
757
759
758
760
$ request = new Optml_Api ();
@@ -776,11 +778,14 @@ public function clear_cache( $type = '' ) {
776
778
if ( empty ( $ type ) || $ type === 'images ' ) {
777
779
set_transient ( 'optml_cache_lock ' , 'yes ' , 5 * MINUTE_IN_SECONDS );
778
780
$ this ->update ( 'cache_buster_images ' , $ data ['token ' ] );
781
+ // we delete individual cache tokens since this is a global cache clear.
782
+ delete_transient ( self ::INDIVIDUAL_CACHE_TOKENS_KEY );
779
783
} elseif ( $ type === 'assets ' ) {
780
784
set_transient ( 'optml_cache_lock_assets ' , 'yes ' , 5 * MINUTE_IN_SECONDS );
781
785
$ this ->update ( 'cache_buster_assets ' , $ data ['token ' ] );
782
786
} else {
783
- set_transient ( '_file_ ' . crc32 ( $ type ), $ data ['token ' ], 6 * HOUR_IN_SECONDS );
787
+ $ individual [ crc32 ( $ type ) ] = $ data ['token ' ];
788
+ set_transient ( self ::INDIVIDUAL_CACHE_TOKENS_KEY , $ individual , 6 * HOUR_IN_SECONDS );
784
789
}
785
790
786
791
return $ data ['token ' ];
0 commit comments