Skip to content

Commit 3eac983

Browse files
committed
Create page cache skeleton
1 parent ea06e3f commit 3eac983

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

src/drop-in/advanced-cache.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/**
4+
* Page cache for WordPress
5+
* Must be placed in wp-content/advanced-cache.php
6+
* It will be loaded when WP_CACHE is true
7+
* See https://developer.wordpress.org/reference/functions/_get_dropins/
8+
*
9+
* This runs before plugins and themes and most WordPress
10+
* code runs, so we only have access to a limited set of
11+
* WordPress functions.
12+
*/
13+
14+
class StaticDeployPageCache {
15+
function capture_output(): void {
16+
$buffering = ob_start([$this, 'receive_output']);
17+
18+
if ($buffering === false) {
19+
error_log('Output buffering failed');
20+
}
21+
}
22+
23+
/**
24+
* Receives the PHP output, which should be the body
25+
* of an HTTP response, and caches it.
26+
*
27+
* This can be called whenever output is flushed,
28+
* and not necessarily when output is finished.
29+
*
30+
* This is the callback provided to ob_start
31+
* https://www.php.net/manual/en/function.ob-start.php
32+
*
33+
* The return value determines the output that is sent
34+
* to the client.
35+
* - A string value: Sent instead of the buffer
36+
* - false: Sends the original output buffer contents
37+
* - true: Sends an empty string instead of the buffer
38+
*/
39+
function receive_output(
40+
string $buffer
41+
): string|bool {
42+
return false;
43+
}
44+
}
45+
46+
new StaticDeployPageCache()->capture_output();

0 commit comments

Comments
 (0)