Skip to content

Commit dde2d6e

Browse files
committed
Merge branch 'release-3.0.0'
2 parents 388c01a + e9981a8 commit dde2d6e

File tree

25 files changed

+936
-775
lines changed

25 files changed

+936
-775
lines changed

.editorconfig

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# https://EditorConfig.org
2+
3+
root = true
4+
5+
[*]
6+
indent_style = space
7+
indent_size = 4
8+
end_of_line = lf
9+
charset = utf-8
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true
12+
block_comment_start = /*
13+
block_comment = *
14+
block_comment_end = */
15+
16+
[**/*.yml]
17+
indent_size = 2
18+
19+
[**/*.md]
20+
trim_trailing_whitespace = false
21+
indent_size = 2
22+
23+
[**/*.json]
24+
indent_size = 2

.gitattributes

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
/.editorconfig export-ignore
12
/.gitattributes export-ignore
23
/.github export-ignore
34
/.gitignore export-ignore
5+
/composer.lock export-ignore
46
/phpcs.xml export-ignore
57
/phpstan.neon export-ignore
6-
/tests export-ignore
8+
/tests export-ignore

.github/workflows/integrate.yml

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow
2+
3+
name: "Integrate"
4+
5+
on:
6+
push:
7+
branches:
8+
- "develop"
9+
- "master"
10+
paths:
11+
- ".github/workflows/**"
12+
- "composer.*"
13+
- "phpcs.xml"
14+
- "phpstan.neon"
15+
- "**.php"
16+
pull_request:
17+
paths:
18+
- ".github/workflows/**"
19+
- "composer.*"
20+
- "phpcs.xml"
21+
- "phpstan.neon"
22+
- "**.php"
23+
# Add [skip ci] to commit message to skip CI.
24+
25+
concurrency:
26+
group: "${{ github.workflow }}-${{ github.ref }}"
27+
cancel-in-progress: true
28+
29+
jobs:
30+
byte_level:
31+
name: "0️⃣ Byte-level"
32+
runs-on: "ubuntu-latest"
33+
steps:
34+
- name: "Checkout code"
35+
uses: "actions/checkout@v3"
36+
37+
- name: "Check file permissions"
38+
run: |
39+
test "$(find . -type f -not -path './.git/*' -executable)" = ""
40+
41+
- name: "Find non-printable ASCII characters"
42+
run: |
43+
#! LC_ALL=C.UTF-8 find . -type f -name '*.php' -print0 | xargs -0 -- grep -PHn '[^ -~Č]' | grep -v '// @ignore-non-ascii$'
44+
! LC_ALL=C.UTF-8 find . -type f -name '*.php' -print0 | xargs -0 -- grep -PHn '[^ -~Č]'
45+
46+
syntax_errors:
47+
name: "1️⃣ Syntax errors"
48+
runs-on: "ubuntu-latest"
49+
steps:
50+
- name: "Set up PHP"
51+
uses: "shivammathur/setup-php@v2"
52+
with:
53+
php-version: "7.3"
54+
extensions: "mbstring"
55+
coverage: "none"
56+
57+
- name: "Checkout code"
58+
uses: "actions/checkout@v3"
59+
60+
- name: "Install dependencies"
61+
uses: "ramsey/composer-install@v2"
62+
with:
63+
dependency-versions: "highest"
64+
65+
- name: "Check source code for syntax errors"
66+
run: "composer exec -- parallel-lint classes/ tests/"
67+
68+
unit_tests:
69+
name: "2️⃣ Unit and functional tests"
70+
needs:
71+
- "byte_level"
72+
- "syntax_errors"
73+
strategy:
74+
#fail-fast: false
75+
matrix:
76+
php-version:
77+
- "8.2"
78+
- "8.1"
79+
- "8.0"
80+
- "7.4"
81+
- "7.3"
82+
dependencies:
83+
- "lowest"
84+
- "locked"
85+
- "highest"
86+
runs-on: "ubuntu-latest"
87+
steps:
88+
- name: "Set up PHP"
89+
uses: "shivammathur/setup-php@v2"
90+
with:
91+
php-version: "${{ matrix.php-version }}"
92+
extensions: "mbstring"
93+
94+
- name: "Checkout code"
95+
uses: "actions/checkout@v3"
96+
97+
- name: "Install dependencies"
98+
uses: "ramsey/composer-install@v2"
99+
with:
100+
dependency-versions: "${{ matrix.dependencies }}"
101+
102+
- name: "Raise constraint for antecedent/patchwork"
103+
if: "${{ matrix.dependencies == 'lowest' }}"
104+
run: "composer require --dev --prefer-lowest --update-with-all-dependencies 'antecedent/patchwork:^2.0.8'"
105+
106+
- name: "Execute unit tests"
107+
run: "composer run-script unit-tests"
108+
# @TODO Functional tests
109+
110+
# - name: "Send coverage to Coveralls"
111+
# env:
112+
# COVERALLS_REPO_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
113+
# if: "${{ env.COVERALLS_REPO_TOKEN && matrix.php-version == '8.1' && matrix.dependencies == 'highest' }}"
114+
# run: |
115+
# wget "https://github.com/php-coveralls/php-coveralls/releases/download/v2.5.2/php-coveralls.phar"
116+
# php ./php-coveralls.phar -v
117+
118+
static_analysis:
119+
name: "3️⃣ Static Analysis"
120+
needs:
121+
- "byte_level"
122+
- "syntax_errors"
123+
runs-on: "ubuntu-latest"
124+
steps:
125+
- name: "Set up PHP"
126+
uses: "shivammathur/setup-php@v2"
127+
with:
128+
php-version: "8.0"
129+
extensions: "mbstring"
130+
coverage: "none"
131+
132+
- name: "Checkout code"
133+
uses: "actions/checkout@v3"
134+
135+
- name: "Validate Composer configuration"
136+
run: "composer validate --strict"
137+
138+
- name: "Install dependencies"
139+
uses: "ramsey/composer-install@v2"
140+
with:
141+
dependency-versions: "highest"
142+
143+
- name: "Check PSR-4 mapping"
144+
run: "composer dump-autoload --optimize --strict-psr"
145+
146+
- name: "Perform static analysis"
147+
run: "composer run-script phpstan"
148+
# @TODO Mess Detector, Magic Number Detector, Copy-Paste Detector
149+
150+
coding_standards:
151+
name: "4️⃣ Coding Standards"
152+
needs:
153+
- "byte_level"
154+
- "syntax_errors"
155+
runs-on: "ubuntu-latest"
156+
steps:
157+
- name: "Set up PHP"
158+
uses: "shivammathur/setup-php@v2"
159+
with:
160+
php-version: "8.0"
161+
extensions: "mbstring"
162+
coverage: "none"
163+
164+
- name: "Checkout code"
165+
uses: "actions/checkout@v3"
166+
167+
- name: "Check EditorConfig configuration"
168+
run: "test -f .editorconfig"
169+
170+
- name: "Check adherence to EditorConfig"
171+
uses: "greut/eclint-action@v0"
172+
173+
- name: "Install dependencies"
174+
uses: "ramsey/composer-install@v2"
175+
with:
176+
dependency-versions: "highest"
177+
178+
- name: "Check coding style"
179+
run: "composer run-script phpcs"
180+
181+
exported_files:
182+
name: "5️⃣ Exported files"
183+
needs:
184+
- "byte_level"
185+
- "syntax_errors"
186+
runs-on: "ubuntu-latest"
187+
steps:
188+
- name: "Checkout code"
189+
uses: "actions/checkout@v3"
190+
191+
- name: "Check exported files"
192+
run: |
193+
EXPECTED="CHANGELOG.md,LICENSE,README.md,autoload.php,bc-cache.php,composer.json"
194+
CURRENT="$(git archive HEAD | tar --list --exclude="classes" --exclude="classes/*" --exclude="assets" --exclude="assets/*" | paste --serial --delimiters=",")"
195+
echo "CURRENT =${CURRENT}"
196+
echo "EXPECTED=${EXPECTED}"
197+
test "${CURRENT}" = "${EXPECTED}"

.github/workflows/php.yml

Lines changed: 0 additions & 50 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# BC Cache Changelog
22

3+
## Upcoming version 3.0.0 (2022-10-13)
4+
5+
This release has been tested with upcoming WordPress 6.1 and PHP 8.2.
6+
7+
### Added
8+
9+
* Add support for caching of HTTP headers [#28](https://github.com/chesio/bc-cache/issues/28). This is a major change and requires an update of `.htaccess` rules! See the [changes](https://github.com/chesio/bc-cache/commit/f3dc91ed7fbafbfeadb39b1b7c86e8cac1a09bea) to `.htaccess` example configuration.
10+
* Core XML sitemaps are now cached as well [#49](https://github.com/chesio/bc-cache/issues/49).
11+
312
## Version 2.3.0 (2022-09-06)
413

514
This release has been tested with WordPress 6.0.

README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Modern and simple full page cache plugin for WordPress inspired by [Cachify](htt
77

88
BC Cache has no settings page - it is intended for webmasters who are familiar with `.htaccess` files and WordPress actions and filters.
99

10+
BC Cache can cache not only HTML pages, but [core XML sitemaps](https://make.wordpress.org/core/2020/07/22/new-xml-sitemaps-functionality-in-wordpress-5-5/) as well. Technically, any content type generated by WordPress for front-end requests routed via root `index.php` file can be handled provided that output generation triggers [`template_redirect`](https://developer.wordpress.org/reference/hooks/template_redirect/) hook.
11+
1012
## Requirements
1113

1214
* Apache webserver with [mod_rewrite](https://httpd.apache.org/docs/current/mod/mod_rewrite.html) enabled
@@ -17,8 +19,7 @@ BC Cache has no settings page - it is intended for webmasters who are familiar w
1719

1820
* BC Cache has not been tested on WordPress multisite installation.
1921
* BC Cache has not been tested on Windows servers.
20-
* BC Cache can only serve requests without filename in path, ie. `/some/path` or `some/other/path/`, but not `/some/path/to/filename.html`.
21-
* BC Cache does not support [content negotation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Content_negotiation#the_accept_header). If contents of URL are deemed cacheable, content is always returned as `text/html` regardless of `Accept` header send by client.
22+
* BC Cache does not support [content negotation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Content_negotiation) via `Accept` header.
2223

2324
## Installation
2425

@@ -85,21 +86,19 @@ AddDefaultCharset utf-8
8586
RewriteCond %{HTTP_HOST} ^([^:]+)(:[0-9]+)?$
8687
RewriteRule .* - [E=BC_CACHE_HOST:%1]
8788
88-
# Set path subdirectory (must end with slash).
89-
RewriteRule .* - [E=BC_CACHE_PATH:%{REQUEST_URI}/]
89+
# Set path subdirectory - its suffix depends on whether URI ends with slash or not.
90+
RewriteRule .* - [E=BC_CACHE_PATH:%{REQUEST_URI}/@file/]
9091
RewriteCond %{REQUEST_URI} /$
91-
RewriteRule .* - [E=BC_CACHE_PATH:%{REQUEST_URI}]
92+
RewriteRule .* - [E=BC_CACHE_PATH:%{REQUEST_URI}@dir/]
9293
9394
# Set request variant (by default there is only empty one).
9495
RewriteRule .* - [E=BC_CACHE_REQUEST_VARIANT:]
9596
96-
# Optionally, serve gzipped version of HTML file.
97-
RewriteRule .* - [E=BC_CACHE_FILE:index%{ENV:BC_CACHE_REQUEST_VARIANT}.html]
97+
# Optionally, serve gzipped version of the file.
98+
RewriteRule .* - [E=BC_CACHE_FILE:index%{ENV:BC_CACHE_REQUEST_VARIANT}]
9899
<IfModule mod_mime.c>
99100
RewriteCond %{HTTP:Accept-Encoding} gzip
100-
RewriteRule .* - [E=BC_CACHE_FILE:index%{ENV:BC_CACHE_REQUEST_VARIANT}.html.gz]
101-
AddType text/html .gz
102-
AddEncoding gzip .gz
101+
RewriteRule .* - [E=BC_CACHE_FILE:index%{ENV:BC_CACHE_REQUEST_VARIANT}.gz]
103102
</IfModule>
104103
105104
# Main rules: serve only GET requests with whitelisted query string fields coming from anonymous users.
@@ -143,6 +142,8 @@ If there was a settings page, following filters would likely become plugin setti
143142

144143
* `bc-cache/filter:can-user-flush-cache` - filters whether current user can clear the cache. By default, any user with `manage_options` capability can clear the cache.
145144
* `bc-cache/filter:html-signature` - filters HTML signature appended to HTML files stored in cache. You can use this filter to get rid of the signature: `add_filter('bc-cache/filter:html-signature', '__return_empty_string');`
145+
* `bc-cache/filter:cached-response-headers` - filters HTTP response headers generated by WordPress/PHP that are kept when cache entry is created. These headers are then sent as additional response headers with cached content. By default following headers are kept: `Content-Type`, `Link`, `X-Pingback`, `X-Robots-Tag`, `X-BC-Cache-Generated`. Note that `Content-Type` header is crucial for proper delivery of cached content and thus is always preserved.
146+
* `bc-cache/filter:cache-generation-timestamp-format` - filters format of cache generation timestamp. This timestamp is included in HTML signature and in `X-BC-Cache-Generated` HTTP response header. The value must be a valid `$format` argument for [`wp_date()`](https://developer.wordpress.org/reference/functions/wp_date/).
146147

147148
#### Filters for advanced functions
148149

@@ -235,7 +236,7 @@ A response to HTTP(S) request is **not** cached by BC Cache if **any** of the co
235236
2. Request is a GET request with one or more query string fields that are not whitelisted. By default, the whitelist consists of [Google click IDs](https://support.google.com/searchads/answer/7342044), [Facebook Click Identifier](https://fbclid.com/) and standard [UTM parameters](https://en.wikipedia.org/wiki/UTM_parameters), but it can be [filtered](#filters).
236237
3. Request is not for a front-end page (ie. [`wp_using_themes`](https://developer.wordpress.org/reference/functions/wp_using_themes/) returns `false`). Output of AJAX, WP-CLI or WP-Cron calls is never cached.
237238
4. Request comes from a non-anonymous user (ie. user that is logged in, left a comment or accessed password protected page/post). The rule can be tweaked to ignore [front-end users](#front-end-users-and-caching) if your theme supports it.
238-
5. Request/response type is one of the following: XML sitemap, search, 404, feed, trackback, robots.txt, preview or password protected post.
239+
5. Request/response type is one of the following: search, 404, feed, trackback, robots.txt, preview or password protected post.
239240
6. [Fatal error recovery mode](https://make.wordpress.org/core/2019/04/16/fatal-error-recovery-mode-in-5-2/) is active.
240241
7. `DONOTCACHEPAGE` constant is set and evaluates to true. This constant is for example [automatically set](https://docs.woocommerce.com/document/configuring-caching-plugins/#section-1) by WooCommerce on certain pages.
241242
8. Return value of `bc-cache/filter:skip-cache` filter evaluates to true.
@@ -285,7 +286,7 @@ This way cached pages can be served to front-end users too. Cookie name and cont
285286

286287
## Request variants
287288

288-
Sometimes a different HTML is served as response to request to the same URL, typically when particular cookie is set or request is made by particular browser/bot. In such cases, BC Cache allows to define request variants and cache/serve different HTML responses based on configured conditions. A typical example is the situation in which privacy policy notice is displayed until site visitor accepts it. The state (cookie policy accepted or not) is often determined based on presence of particular cookie. Using request variants, BC Cache can serve visitors regardless if they have or have not accepted the cookie policy.
289+
Sometimes a different response body is served to request to the same URL, typically when particular cookie is set or request is made by particular browser/bot. In such cases, BC Cache allows to define request variants and cache/serve different response body based on configured conditions. A typical example is the situation in which privacy policy notice is displayed until site visitor accepts it. The state (cookie policy accepted or not) is often determined based on presence of particular cookie. Using request variants, BC Cache can serve visitors regardless if they have or have not accepted the cookie policy.
289290

290291
### Request variant configuration example
291292

@@ -312,7 +313,7 @@ The [default configuration](#installation) needs to be extended as well and set
312313
RewriteRule .* - [E=BC_CACHE_REQUEST_VARIANT:_cna]
313314
```
314315

315-
Important: Variant names are appended to basename part of cache file names, so `index.html` becomes `index_cna.html` and `index.html.gz` becomes `index_cna.html.gz` in the example above. To make sure your setup will work, use only letters from `[a-z0-9_-]` range as variant names.
316+
Important: Variant names are appended to basename part of cache file names, so `index` becomes `index_cna` and `index.gz` becomes `index_cna.gz` in the example above. To make sure your setup will work, use only letters from `[a-z0-9_-]` range as variant names.
316317

317318
## Cache warm up
318319

assets/icons.svg

Lines changed: 5 additions & 5 deletions
Loading

0 commit comments

Comments
 (0)