{"id":19098560,"url":"https://github.com/airesvsg/wp-rest-api-cache","last_synced_at":"2025-04-06T06:11:45.559Z","repository":{"id":56942840,"uuid":"59378938","full_name":"airesvsg/wp-rest-api-cache","owner":"airesvsg","description":"Enable caching for WordPress REST API and increase speed of your application","archived":false,"fork":false,"pushed_at":"2019-02-28T13:02:34.000Z","size":12,"stargazers_count":244,"open_issues_count":10,"forks_count":35,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-30T05:07:01.139Z","etag":null,"topics":["api","cache","rest","rest-api","wordpress","wp"],"latest_commit_sha":null,"homepage":"http://wordpress.org/plugins/wp-rest-api-cache","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/airesvsg.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-21T19:54:50.000Z","updated_at":"2025-03-14T03:57:37.000Z","dependencies_parsed_at":"2022-08-21T02:10:23.394Z","dependency_job_id":null,"html_url":"https://github.com/airesvsg/wp-rest-api-cache","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/airesvsg%2Fwp-rest-api-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/airesvsg%2Fwp-rest-api-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/airesvsg%2Fwp-rest-api-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/airesvsg%2Fwp-rest-api-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/airesvsg","download_url":"https://codeload.github.com/airesvsg/wp-rest-api-cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247441055,"owners_count":20939239,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","cache","rest","rest-api","wordpress","wp"],"created_at":"2024-11-09T03:46:17.076Z","updated_at":"2025-04-06T06:11:45.534Z","avatar_url":"https://github.com/airesvsg.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"WP REST API Cache\n====\nEnable caching for WordPress REST API and increase speed of your application\n\n- [Installation](#installation)\n- [Filters](#filters)\n- [How to use filters](#how-to-use-filters)\n\nInstallation\n====\n1. Copy the `wp-rest-api-cache` folder into your `wp-content/plugins` folder\n2. Activate the `WP REST API Cache` plugin via the plugin admin page\n\nFilters\n====\n| Filter    | Argument(s) |\n|-----------|-----------|\n| rest_cache_headers | array **$headers**\u003cbr\u003estring **$request_uri**\u003cbr\u003eWP_REST_Server **$server**\u003cbr\u003eWP_REST_Request **$request** |\n| rest_cache_skip | boolean **$skip** ( default: WP_DEBUG )\u003cbr\u003estring **$request_uri**\u003cbr\u003eWP_REST_Server **$server**\u003cbr\u003eWP_REST_Request **$request** |\n| rest_cache_key | string **$request_uri**\u003cbr\u003eWP_REST_Server **$server**\u003cbr\u003eWP_REST_Request **$request** |\n| rest_cache_timeout | int **$timeout**\u003cbr\u003eint **$length**\u003cbr\u003eint **$period** |\n| rest_cache_update_options | array **$options** |\n| rest_cache_get_options | array **$options** |\n| rest_cache_show_admin | boolean **$show** |\n| rest_cache_show_admin_menu | boolean **$show** |\n| rest_cache_show_admin_bar_menu | boolean **$show** |\n\nHow to use filters\n----\n- **sending headers**\n\n```PHP\nadd_filter( 'rest_cache_headers', function( $headers ) {\n\t$headers['Cache-Control'] = 'public, max-age=3600';\n\t\n\treturn $headers;\n} );\n```\n\n- **changing the cache timeout**\n\n```PHP\nadd_filter( 'rest_cache_timeout', function() {\n\t// https://codex.wordpress.org/Transients_API#Using_Time_Constants\n\treturn 15 * DAY_IN_SECONDS;\n} );\n```\nor\n```PHP\nadd_filter( 'rest_cache_get_options', function( $options ) {\n\tif ( ! isset( $options['timeout'] ) ) {\n\t\t$options['timeout'] = array();\n\t}\n\n\t// https://codex.wordpress.org/Transients_API#Using_Time_Constants\n\t$options['timeout']['length'] = 15;\n\t$options['timeout']['period'] = DAY_IN_SECONDS;\n\t\n\treturn $options;\n} );\n```\n\n- **skipping cache**\n\n```PHP\nadd_filter( 'rest_cache_skip', function( $skip, $request_uri ) {\n\tif ( ! $skip \u0026\u0026 false !== stripos( $request_uri, 'wp-json/acf/v2' ) ) {\n\t\treturn true;\n\t}\n\n\treturn $skip;\n}, 10, 2 );\n```\n\n- **show / hide admin links**\n\n![WP REST API Cache](http://airesgoncalves.com.br/screenshot/wp-rest-api-cache/readme/filter-admin-show.gif)\n\n- **empty cache on post-save**\n\nYou 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.\n\n```PHP\nadd_action( 'save_post', function( $post_id ) {\n  if ( class_exists( 'WP_REST_Cache' ) ) {\n    WP_REST_Cache::empty_cache();\n  }\n} );\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fairesvsg%2Fwp-rest-api-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fairesvsg%2Fwp-rest-api-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fairesvsg%2Fwp-rest-api-cache/lists"}