All Projects → airesvsg → Wp Rest Api Cache

airesvsg / Wp Rest Api Cache

Enable caching for WordPress REST API and increase speed of your application

Projects that are alternatives of or similar to Wp Rest Api Cache

Acf To Rest Api
Exposes Advanced Custom Fields Endpoints in the WordPress REST API
Stars: ✭ 1,152 (+382.01%)
Mutual labels:  api, rest-api, rest, wordpress
Jda
Java wrapper for the popular chat & VOIP service: Discord https://discord.com
Stars: ✭ 2,598 (+987.03%)
Mutual labels:  api, rest-api, rest
Symfony Flex Backend
Symfony Flex REST API template project
Stars: ✭ 214 (-10.46%)
Mutual labels:  api, rest-api, rest
Mockoon
Mockoon is the easiest and quickest way to run mock APIs locally. No remote deployment, no account required, open source.
Stars: ✭ 3,448 (+1342.68%)
Mutual labels:  api, rest-api, rest
Magic
Create your .Net Core/Angular/Database CRUD Web apps by simply clicking a button
Stars: ✭ 214 (-10.46%)
Mutual labels:  api, rest-api, rest
Appkernel
API development made easy: a smart Python 3 API framework
Stars: ✭ 152 (-36.4%)
Mutual labels:  api, rest-api, rest
Bookmarks.dev
Bookmarks and Code Snippets Manager for Developers & Co
Stars: ✭ 218 (-8.79%)
Mutual labels:  api, rest-api, rest
Poloniex Api Node
Poloniex API client for REST and WebSocket API
Stars: ✭ 138 (-42.26%)
Mutual labels:  api, rest-api, rest
Storefront Api
Storefront GraphQL API Gateway. Modular architecture. ElasticSearch included. Works great with Magento1, Magento2, Spree, OpenCart, Pimcore and custom backends
Stars: ✭ 180 (-24.69%)
Mutual labels:  api, rest-api, rest
Graphql2rest
GraphQL to REST converter: automatically generate a RESTful API from your existing GraphQL API
Stars: ✭ 181 (-24.27%)
Mutual labels:  api, rest-api, rest
Lumen Microservice
Lumen on Docker - Skeleton project with Nginx, MySQL & PHP 7 | Aws ECS, Google Kubernates, Azure Container Engine
Stars: ✭ 183 (-23.43%)
Mutual labels:  api, rest-api, rest
Api Guidelines
adidas group API design guidelines
Stars: ✭ 147 (-38.49%)
Mutual labels:  api, rest-api, rest
Node Express Mongoose Passport Jwt Rest Api Auth
Node, express, mongoose, passport and JWT REST API authentication example
Stars: ✭ 146 (-38.91%)
Mutual labels:  api, rest-api, rest
Pop
Monorepo of the PoP project, including: a server-side component model in PHP, a GraphQL server, a GraphQL API plugin for WordPress, and a website builder
Stars: ✭ 160 (-33.05%)
Mutual labels:  api, rest-api, wordpress
Grafanajsondatasource
Grafana datasource to load JSON data over your arbitrary HTTP backend
Stars: ✭ 146 (-38.91%)
Mutual labels:  api, rest-api, rest
Rest Api Slim Php
Example of REST API with Slim PHP Framework.
Stars: ✭ 165 (-30.96%)
Mutual labels:  api, rest-api, rest
Co Cart
🛒 CoCart is a flexible, open-source solution to enabling the shopping cart via the REST API for WooCommerce.
Stars: ✭ 198 (-17.15%)
Mutual labels:  api, rest-api, wordpress
Open Rest
Standard rest server, Base on restify and sequelize
Stars: ✭ 136 (-43.1%)
Mutual labels:  api, rest-api, rest
React With Wordpress
🔥 Example of react application to access WordPress REST API
Stars: ✭ 137 (-42.68%)
Mutual labels:  api, rest-api, wordpress
Proteus
Lean, mean, and incredibly fast JVM framework for web and microservice development.
Stars: ✭ 178 (-25.52%)
Mutual labels:  api, rest-api, rest

WP REST API Cache

Enable caching for WordPress REST API and increase speed of your application

Installation

  1. Copy the wp-rest-api-cache folder into your wp-content/plugins folder
  2. Activate the WP REST API Cache plugin 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

WP REST API Cache

  • 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();
  }
} );
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].