Proyek
Lihat di GitHub
airesvsg/wp-rest-api-cache
Tentang
Enable caching for WordPress REST API and increase speed of your application
Pengembangan web dan aplikasiPertumbuhan bintang terukur
- dalam 24 jam
- 0
- dalam 7 hari
- 0
- dalam 15 hari
- 0
- dalam 1 bulan
- Mengumpulkan riwayat
Perubahan bersih pada periode yang tumpang tindih, bukan total harian. Pengukuran yang belum tersedia dibiarkan kosong. Bintang menunjukkan perhatian, bukan kualitas.
README.md
AsliWP REST API Cache
Enable caching for WordPress REST API and increase speed of your application
Installation
- Copy the
wp-rest-api-cachefolder into yourwp-content/pluginsfolder - Activate the
WP REST API Cacheplugin via the plugin admin page
Filters
| Filter | Argument(s) |
|---|---|
| rest_cache_headers | array $headers string $request_uri WP_REST_Server $server WP_REST_Request $request |
| rest_cache_skip | boolean $skip ( default: WP_DEBUG ) string $request_uri WP_REST_Server $server WP_REST_Request $request |
| rest_cache_key | string $request_uri WP_REST_Server $server WP_REST_Request $request |
| rest_cache_timeout | int $timeout int $length int $period |
| rest_cache_update_options | array $options |
| rest_cache_get_options | array $options |
| rest_cache_show_admin | boolean $show |
| rest_cache_show_admin_menu | boolean $show |
| rest_cache_show_admin_bar_menu | boolean $show |
How to use filters
- sending headers
add_filter( 'rest_cache_headers', function( $headers ) {
$headers['Cache-Control'] = 'public, max-age=3600';
return $headers;
} );
- changing the cache timeout
add_filter( 'rest_cache_timeout', function() {
// https://codex.wordpress.org/Transients_API#Using_Time_Constants
return 15 * DAY_IN_SECONDS;
} );
or
add_filter( 'rest_cache_get_options', function( $options ) {
if ( ! isset( $options['timeout'] ) ) {
$options['timeout'] = array();
}
// https://codex.wordpress.org/Transients_API#Using_Time_Constants
$options['timeout']['length'] = 15;
$options['timeout']['period'] = DAY_IN_SECONDS;
return $options;
} );
- skipping cache
add_filter( 'rest_cache_skip', function( $skip, $request_uri ) {
if ( ! $skip && false !== stripos( $request_uri, 'wp-json/acf/v2' ) ) {
return true;
}
return $skip;
}, 10, 2 );
- show / hide admin links

- empty cache on post-save
You can use the wordpress default filter "save_post" if you like to empty the cache on every save of a post, page or custom post type.
add_action( 'save_post', function( $post_id ) {
if ( class_exists( 'WP_REST_Cache' ) ) {
WP_REST_Cache::empty_cache();
}
} );
Jelajahi proyek terkait
Memuat…