@@ -120,12 +120,44 @@ public function purge_url( $url, $feed = true ) {
120
120
121
121
$ prefix = $ nginx_helper_admin ->options ['redis_prefix ' ];
122
122
$ _url_purge_base = $ prefix . $ parse ['scheme ' ] . 'GET ' . $ parse ['host ' ] . $ parse ['path ' ];
123
- $ is_purged = $ this ->delete_single_key ( $ _url_purge_base );
124
123
125
- if ( $ is_purged ) {
126
- $ this ->log ( '- Purged URL | ' . $ url );
124
+ /**
125
+ * To delete device type caches such as `<URL>--mobile`, `<URL>--desktop`, `<URL>--lowend`, etc.
126
+ * This would need $url above to be changed with this filter `rt_nginx_helper_purge_url` by cache key that Nginx sets while generating cache.
127
+ *
128
+ * For example: If page is accessed from desktop, then cache will be generated by appending `--desktop` to current URL.
129
+ * Add this filter in separate plugin or simply in theme's function.php file:
130
+ * ```
131
+ * add_filter( 'rt_nginx_helper_purge_url', function( $url ) {
132
+ * $url = $url . '--*';
133
+ * return $url;
134
+ * });
135
+ * ```
136
+ *
137
+ * Regardless of what key / suffix is being to store `$device_type` cache , it will be deleted.
138
+ *
139
+ * @since 2.1.0
140
+ */
141
+ if ( strpos ( $ _url_purge_base , '* ' ) === false ) {
142
+
143
+ $ status = $ this ->delete_single_key ( $ _url_purge_base );
144
+
145
+ if ( $ status ) {
146
+ $ this ->log ( '- Purge URL | ' . $ _url_purge_base );
147
+ } else {
148
+ $ this ->log ( '- Cache Not Found | ' . $ _url_purge_base , 'ERROR ' );
149
+ }
150
+
127
151
} else {
128
- $ this ->log ( '- Cache Not Found | ' . $ url , 'ERROR ' );
152
+
153
+ $ status = $ this ->delete_keys_by_wildcard ( $ _url_purge_base );
154
+
155
+ if ( $ status ) {
156
+ $ this ->log ( '- Purge Wild Card URL | ' . $ _url_purge_base . ' | ' . $ status . ' url purged ' );
157
+ } else {
158
+ $ this ->log ( '- Cache Not Found | ' . $ _url_purge_base , 'ERROR ' );
159
+ }
160
+
129
161
}
130
162
131
163
$ this ->log ( '* * * * * ' );
0 commit comments