Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Add caching of post processor output #959
The preprocessor/sanitizer can be an expensive series of operations. If we take a hash of the pre-sanitized HTML and use this as the cache key for caching the sanitized output, it would be possible to short-circuit the entire sanitization process by serving the cache output directly. This would not preclude full page caches since PHP would still be generating the buffered output, but it would be a good way to augment full page caches. Props @ThierryA for the idea.
This can be done after #1048 since it includes the
The cache key used for should consist of a hash of the output buffer with the plugin version and perhaps the list of sanitizers and embed handlers being used. If a plugin or theme is installed which adds another sanitizer or embed handler, this will impact the sanitizer/post-processor output, so it should be part of the cache key.
Reference the code used in the CSS processor caching: https://github.com/Automattic/amp-wp/blob/14c22c2f25490df3d1899fa1f71e969574372d90/includes/sanitizers/class-amp-style-sanitizer.php#L496-L515
I don't think that a transient should necessarily be used for caching the output since if an external object cache is not installed this can result in the options table exploding with transients. That being said, transients are being used now to store the result of image dimension lookup requests, but that is not ideal either. See also #960 where we'll warn users that they should have an external object cache present.