wp-graphql / wp-graphql-smart-cache

Smart Caching & Cache Invalidation for WPGraphQL
60 stars 14 forks source link

Flywheel cache integration for wp-graphql #115

Closed bhardie closed 1 year ago

bhardie commented 2 years ago

To support requests over GET, we need to support invalidating cache in the stack when content changes on the backend.

When content changes (post, customer post type, tag, category, etc), purge specific urls from Flywheel cache.

Example graphql query paths: /graphql?queryId=query-posts&variables={ id: 1 } /graphql?query={ posts {nodes { title } } /custom?queryId=query-home-page

Create a flywheel site

markkelnar commented 2 years ago

I created a flywheel site. Confirmed wp-graphql GEt requests are cached and not invalidated when content changes. Confirmed regular post/pages do change when content changes. This means there is cache invalidation to fastly.

Reached out to Andy about how to hook into the cache invalidation plugin, function, process. Still waiting on details of how to do that.

markkelnar commented 2 years ago

Dug through and found a file called /flywheel-plugins/flywheel-activity-monitor/flywheel-activity-monitor.php that runs on save_post action (and others). It writes a specific formatted log message to the php error log error_log( "FW_EVENT: " json_encode( .... )

I've played around with mimicking, adding, tweaking to get /graphql/queryId= paths to purge, but gonna need someone from flywheel team to help. Maybe means something needs to be added to their log filter process to look for my graphql trigger/event and paths.

Another idea is in the fw_post_logger() function that creates the data that is writen to this FW_EVENT log, maybe there could be a filter for my plugin to add urls to be purged when the post even happens. Similar to what the WPE function does. But also gonna need support for ACF and ACM postmeta actions when custom post types change.

But for right now, I can't trigger the purge for graphql paths like I thought I could.

jasonmfrazier commented 2 years ago

I've created https://wpengine.atlassian.net/browse/FCP-2227?atlOrigin=eyJpIjoiNjQxYTdhNGUzYmVlNDljMThkYWNkZDIzZjgwN2Y2MmQiLCJwIjoiaiJ9 in the Flywheel Cloud Platform team's backlog. I am going to need a bit of context/business justification in order to appropriately prioritize this work for the team.

markkelnar commented 2 years ago

Worked with DanFitch to get info needed to use a fw logging function. Mostly there. Gonna do more testing. :+1:

markkelnar commented 1 year ago

We have refactored the graphql_purge action to listen for. Working to make that change in WPE farm. I think we close this until there is a flywheel need and make use of a similar purge mechism outside the smart-cache plugin, but in a vendor specific plugin.