{"id":19354593,"url":"https://github.com/wp-graphql/wp-graphql-smart-cache","last_synced_at":"2025-12-16T02:58:17.470Z","repository":{"id":41358845,"uuid":"375088351","full_name":"wp-graphql/wp-graphql-smart-cache","owner":"wp-graphql","description":"Smart Caching \u0026 Cache Invalidation for WPGraphQL","archived":false,"fork":false,"pushed_at":"2024-09-04T17:02:12.000Z","size":9195,"stargazers_count":60,"open_issues_count":29,"forks_count":14,"subscribers_count":10,"default_branch":"main","last_synced_at":"2024-10-29T22:37:53.273Z","etag":null,"topics":["cache","graphql","plugin","wordpress","wpgraphql"],"latest_commit_sha":null,"homepage":"","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/wp-graphql.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-08T17:14:54.000Z","updated_at":"2024-09-04T17:02:05.000Z","dependencies_parsed_at":"2023-09-24T12:10:31.576Z","dependency_job_id":"0813a2cf-05a8-4316-9956-397663fb22ad","html_url":"https://github.com/wp-graphql/wp-graphql-smart-cache","commit_stats":{"total_commits":623,"total_committers":13,"mean_commits":47.92307692307692,"dds":0.478330658105939,"last_synced_commit":"5ffd6f59538800342ec2257754b7d9e5d8638c9e"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-graphql%2Fwp-graphql-smart-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-graphql%2Fwp-graphql-smart-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-graphql%2Fwp-graphql-smart-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-graphql%2Fwp-graphql-smart-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wp-graphql","download_url":"https://codeload.github.com/wp-graphql/wp-graphql-smart-cache/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248036063,"owners_count":21037092,"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":["cache","graphql","plugin","wordpress","wpgraphql"],"created_at":"2024-11-10T05:02:43.903Z","updated_at":"2025-12-16T02:58:17.377Z","avatar_url":"https://github.com/wp-graphql.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"./docs/images/logo-wp-graphql-smart-cache.jpg\" width=\"150px\" /\u003e\n\n# WPGraphQL Smart Cache\n\nDo you want your API data _fast_ or _accurate_? With WPGraphQL Smart Cache, you can have both.\n\nWPGraphQL Smart Cache is a free, open-source WordPress plugin that provides support for caching and cache invalidation of WPGraphQL Queries.\n\nTo get the most out of this plugin, we recommend using GET requests with Network Caching, which requires your WordPress install to be on a [supported host](https://github.com/wp-graphql/wp-graphql-smart-cache/blob/main/docs/network-cache.md#supported-hosts).\n\n**BREAKING CHANGES:** We may make breaking changes in the future to improve functionality and experience. If we do, we will use semver to do so. Pay attention to release notes and upgrade notices before updating.\n\n----\n\n## Video Overview\n\n\u003ca href=\"https://youtu.be/t_y6q02q7K4\" target=\"_blank\"\u003e\u003cimg src=\"./docs/images/banner-wp-graphql-smart-cache-v1.jpg\" width=\"640px\" /\u003e\u003c/a\u003e\n\n----\n## Docs 📖\n\n- [Overview](#overview)\n- [Quick Start](#-quick-start)\n- Features\n  - [Network Cache](./docs/network-cache.md)\n  - [Object Cache](./docs/object-cache.md)\n  - [Persisted Queries](./docs/persisted-queries.md)\n  - [Cache Invalidation](./docs/cache-invalidation.md)\n- [Extending / Customizing Functionality](./docs/extending.md)\n- [FAQ and Troubleshooting](#faq--troubleshooting)\n- [Known Issues](#known-issues)\n- [Providing Feedback](#providing-feedback)\n\n----\n\n## Overview\n\nWPGraphQL has essentially become the standard when it comes to building headless WordPress experiences.\n\nThe flexibility and tooling around GraphQL is attractive, but it can come at a cost.\n\n### Performance Issues\n\n_\"The fastest code is the code which does not run\" - [Robert Galanakis](https://daveredfern.com/no-code/)_\n\nWPGraphQL is optimized for run-time performance by using [DataLoader](https://www.wpgraphql.com/docs/wpgraphql-vs-wp-rest-api#dataloader-and-the-n1-problem) methods and other techniques to reduce run time execution cost, but the fact is that WPGraphQL is built on top of WordPress and respects the WordPress application layer – including actions, filters, authentication rules, and the WordPress database structure.\n\nThis means that anytime a WPGraphQL request is executed against WordPress (much like any type of request made to WordPress) there is a cost, and the cost can sometimes be problematic.\n\nOne of the fastest ways to load WordPress, is to prevent WordPress from being loaded at all!\n\nThis is no different for WPGraphQL.\n\n### Solving the Performance Issues\n\nThis is where WPGraphQL Smart Cache comes in.\n\nWPGraphQL Smart Cache has integrations with a multiple layers of caching to provide users of WPGraphQL with both fast and accurate data managed in WordPress.\n\nThe over-simplification of WPGraphQL Smart Cache, is to capture the results of GraphQL Requests, store the response in a cache, and use the cached response for future requests instead of executing the query and all of its resolvers at each request.\n\n----\n\n## 🚀 Quick Start\n\nThis quick start guide will cover the basics of [Object Caching for WPGraphQL Queries](./docs/object-cache.md) and [Cache Invalidation](./docs/cache-invalidation.md).\n\n\u003e _If you're WordPress install is on a [supported host](./docs/network-cache.md#supported-hosts), you will benefit more from Network Caching and we recommend you head over to the [Network Cache Quick Start](./docs/network-cache.md#quick-start) instead of this quick-start. If you're not on a supported host, tell your host to check out our [hosting guide](./docs/network-cache.md#hosting-guide) and carry on with this Quick Start guide below._\n\n----\n\n### 📖 Quick Start Guide\n\n- [Install \u0026 Activate](#install--activate)\n- [Enable WPGraphQL Object Cache](#enable-wpgraphql-object-cache)\n- [Enable WPGraphQL Tracing (optional)](#enable-wpgraphql-tracing-optional)\n- [Execute a query in GraphiQL IDE](#execute-a-query-using-the-graphiql-ide)\n- [Execute the same query again](#execute-the-query-again)\n- [Invalidate the Cache](#invalidate-the-cache)\n\n---\n\n### Install \u0026 Activate\n\nIf you haven't already installed and activated the WPGraphQL Smart Cache plugin, follow the [Install \u0026 Activation guide](./docs/installation.md), then come back here.\n\n### Enable WPGraphQL Object Cache\n\nWith the latest versions of WPGraphQL and WPGraphQL Smart Cache installed and activated, navigate to the \"WPGraphQL \u003e Settings\" page in your WordPress dashboard, then select the \"Cache\" tab.\n\n![Screenshot of the WPGraphQL Smart Cache \"Cache\" Settings](./docs/images/object-cache-enable.png)\n\nFrom this settings page, check the \"Use Object Cache\" setting and click \"Save Changes\".\n\nThis will activate the object cache functionality for WPGraphQL Queries.\n\n### Enable WPGraphQL Tracing (optional)\n\nWhile testing, you can enable \"WPGraphQL Tracing\" to see data about how long (in microseconds) each field in a GraphQL request takes to resolve.\n\nTo enable WPGraphQL Tracing, navigate to the \"WPGraphQL \u003e Settings\" page and select the \"WPGraphQL General Settings\" tab.\n\nCheck the \"Enable GraphQL Tracing\" option, and set the \"Tracing Role\" to \"Any\". This will let us see the trace data in public requests as we test the caching functionality.\n\n![Screenshot of enabling Tracing in WPGraphQL Settings](./docs/images/enable-graphql-tracing.png)\n\n\u003e **NOTE:** When you're done testing, consider disabling tracing as it is intended to be a debug tool, and it does add weight to the responses client applications download from the WPGraphQL Server.\n\n### Execute a query using the GraphiQL IDE\n\nNext, navigate to the \"GraphQL \u003e GraphiQL IDE\" screen in the WordPress dashboard.\n\nPaste the following query in the IDE.\n\n```graphql\n{\n  posts {\n    nodes {\n      id\n      title\n      uri\n    }\n  }\n}\n```\n\nExecute the query by pressing the play button.\n\n\u003e _**NOTE:** To ensure your GraphiQL IDE is not executing as a logged in user, toggle the button to the right of the \"Play\" button. If a green status indicator is showing, requests will be authenticated and will bypass the cache. Public, non-authenticated requests will be served from the cache._\n\nYou should see results similar to the following screenshot:\n\n![Screenshot of uncached query](./docs/images/graphiql-execute-first-query.png)\n\nIf you inspect the response, you will notice the \"graphqlSmartCache\" key with a nested \"graphqlObjectCache\" key under the \"extensions\" payload.\n\nIf the value of the `graphqlObjectCache` key is empty, the request was _not_ served from cache.\n\nIf you [enabled GraphQL Tracing](#enable-wpgraphql-tracing-optional), take a look at the `extensions.tracing\" payload.\n\nYou will see a \"duration\" field, which is the overall time the query took to resolve (in microseconds).\n\nTake note of this value. For me, it was: `\"duration\": 23271,`\n\nAdditionally, you will see a lot of data about each field that was resolved. You don't need any of this data, just take note of its presence.\n\n### Execute the Query Again\n\nExecute the same query again (still as a non-authenticated request).\n\nThis time, you should observe the `graphqlSmartCache.graphqlObjectCache` key will have data returned.\n\nYou should see a payload similar to the following:\n\n```json\n {\n  \"data\": {\n    ...\n  },\n  \"extensions\": {\n    ...\n    \"graphqlSmartCache\": {\n      \"graphqlObjectCache\": {\n        \"message\": \"This response was not executed at run-time but has been returned from the GraphQL Object Cache\",\n        \"cacheKey\": \"9cc3bbab3abfcc618153b3e9a3df403c2408f1007abe35aeaec0e2d640fb1233\"\n      }\n    }\n  }\n}\n```\n\nThis means that the request was served from the WPGraphQL Object Cache instead of executing all of the resolvers for every field.\n\nIf you [enabled GraphQL Tracing](#enable-wpgraphql-tracing-optional), take a look at the `extensions.tracing\" payload again.\n\nThis time, you should see a lower value for the duration field. For me, the value was `\"duration\": 9933`. Nearly 3x faster!\n\nAdditionally, you will note that the `resolvers` field under tracing is empty. This is because the data was returned from the object cache and no resolvers were executed!\n\n### Invalidate the Cache\n\nGo ahead and execute the same query a few more times, and note that it continues to be served from the cache.\n\nIn order to balance \"Fast\" and \"Accurate\" data, WPGraphQL Smart Cache listens to events in WordPress, and when relevant events occur, the relevant cache(s) are evicted, and fresh data is served.\n\nIn another browser tab, navigate to the \"Posts\" page and \"quick edit\" the most recent post, adding a period to the title.\n\n![Screen recording showing a quick-edit of a post's title](./docs/images/quick-edit-post-title.gif)\n\nThen, back in the browser tab with the GraphiQL IDE open, execute the query again.\n\nThe query should be a \"cache miss\" and we should see the accurate, updated title, and the `graphqlSmartCache.graphqlObjectCache\" output under \"extensions\" should be empty.\n\n![Screen shot of the updated, uncached query](./docs/images/graphql-query-updated-data.png)\n\n----\n\n##  👉 Next Steps\n\nNow that you've completed the quick start, continue on learn more about the features of the WPGraphQL Smart Cache plugin.\n\n### Features\n- [Network Cache](./docs/network-cache.md)\n- [Object Cache](./docs/object-cache.md)\n- [Persisted Queries](./docs/persisted-queries.md)\n- [Cache Invalidation](./docs/cache-invalidation.md)\n\n### Additional Docs\n\n- [Extending / Customizing Functionality](./docs/extending.md)\n- [FAQ and Troubleshooting](./docs/faq.md)\n- [Known Issues](#known-issues)\n- [Providing Feedback](#providing-feedback)\n\n### Related Links 🔗\n\n- [WPGraphQL.com](https://www.wpgraphql.com)\n- [WP Engine Atlas](https://www.wpengine.com/atlas)\n\n----\n\n## Known Issues\n\n### Batch Queries\n\nThere are currently some issues around Batch Queries. If you use Batch Queries in your client application, we will need more time before we have WPGraphQL Smart Cache working for you.\n\nIf you use Batch Queries in your application and would like to make use of WPGraphQL Smart Cache, let us know in the WPGraphQL Smart Cache slack channel or GitHub Discussions so we can learn more about your use cases.\n\n### Missing Invalidation Hooks\n\nCurrently, we’re missing invalidation hooks related to Settings (options).\n\nThat means cache for queries that ask for Settings (i.e General Settings, Discussion Settings, etc) will not be invalidated/evicted automatically when actions related to those things occur.\n\nYou can read more about the nuances of supporting settings here: [#158](https://github.com/wp-graphql/wp-graphql-smart-cache/issues/158)\n\n----\n\n## Providing Feedback\n\nIf you have feedback after using WPGraphQL Smart Cache, we would love to hear it!\n\n### Issues \u0026 Bug Reports\n\nIf you have an issue or a bug to report, the best place to do that is in the GitHub Repository: [https://github.com/wp-graphql/wp-graphql-smart-cache/issues](https://github.com/wp-graphql/wp-graphql-smart-cache/issues)\n\n### Feature Requests\n\nIf you have an idea for a feature that feels like it would be a nice addition to the WPGraphQL Smart Cache plugin, you can let us know in the Discussion section of the GitHub Repository: [https://github.com/wp-graphql/wp-graphql-smart-cache/discussions](https://github.com/wp-graphql/wp-graphql-smart-cache/discussions)\n\n### General Discussion\n\nFor general discussion about the plugin, you can visit the WPGraphQL Slack ([join here](https://wp-graphql.slack.com/join/shared_invite/zt-3vloo60z-PpJV2PFIwEathWDOxCTTLA#/shared-invite/email)) and join the `#wp-graphql-smart-cache` channel, or post in the [GitHub Discussions](https://github.com/wp-graphql/wp-graphql-smart-cache/discussions).\n\n### Security Concerns\n\nIf you believe you’ve found something in the WPGraphQL Smart Cache codebase that could be a security concern, please let us know by emailing us directly at [info@wpgraphql.com](mailto:info@wpgraphql.com).\n\nPlease do not email other bug reports, feature requests or support questions to this email address.\n\n----\n\n## Privacy Policy\n\nWPGraphQL Smart Cache uses [Appsero](https://appsero.com) SDK to collect some telemetry data upon user's confirmation. This helps us to troubleshoot problems faster \u0026 make product improvements.\n\nAppsero SDK **does not gather any data by default.** The SDK only starts gathering basic telemetry data **when a user allows it via the admin notice**. We collect the data to ensure a great user experience for all our users.\n\nIntegrating Appsero SDK **DOES NOT IMMEDIATELY** start gathering data, **without confirmation from users in any case.**\n\nLearn more about how [Appsero collects and uses this data](https://appsero.com/privacy-policy/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwp-graphql%2Fwp-graphql-smart-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwp-graphql%2Fwp-graphql-smart-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwp-graphql%2Fwp-graphql-smart-cache/lists"}