Skip to main content

Developer guide to Caching and Purging

There are essentially 4 places to look

  1. CachePurge see section in github Where it knows how to purge, what types of purge are possible, if things should be queued for purging.
  • Drivers: The drivers that are possible to be used [Cloudflare, Servebolt, ServeboltCDN], they implement the interfaces.
  • Interfaces: The different functions each interface can do, ie. purgeAll(), purgeTerm()
  • PurgeObject: The different types of purge object that can be created [post, cachetag,term].
  • WordPressCachePurge: The different ways its performs the Purge, with a manager class
  • WpObjectCachePurgeActions: Where actions are configured, for example on “post_save” perform a purge event.
  1. CacheTags see section in github are setup here. This does not do any purging its self, it just checks if its suitable to add cache tags to a site, and when purging checks if cache tags can be used there also, and resolve what ones to use.
  2. FullPageCache see section in github Where it defined headers or anything else to do with cache timeouts.
  3. Queue see section in github optional queuing of purge events that are worked on every Cron event, usually every minute on a busy, crontab dependent. The queue saved “stubs” that it works on when it gets to it. The stub is a reference to what is going to be pruged, it is only when it is works on finding actual urls or cach tags will be purged in relation to the stub.

How it works

  1. There is a requirement to perform a CRUD, that requires a purge
  2. The system works out via that request if it should be a Post, CacheTag or a Term purge
  3. It loads the CachePurge/PurgeObject/ObjectTypes needed
  4. For Post it uses CachePurge/WordPressCachePurge/PostMethods.php, for Terms TermMethods.php
  5. If the loaded ObjectType is not CacheTags, it purges by url for each possible url related to the post or term. If it is using cacheTags it generates the headers that way example see purgePostCache() and purgeTermCache(). There are lots of other methods that perform the wordpress cache purge from these two files.
  6. It then loads the correct Cache Driver for the setup, and checks what type of purge events are open to it via an Interface implementation. It then tries to run the wanted method purge the cache via either the Servebolt API or direct with Cloudflare.
  7. Then via the correct route for the API endpoint wanted it makes a call to these API’s via the Servebolt PHP-SDK

If the queue is turned on it puts a stub in the queue at Step #1. Which it then reads when it gets to in in the queue, and then starts Step #2