diff --git a/README.md b/README.md index 4d21057..ddafc16 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,47 @@ -# Longcache +# Smartcache -Longcache will set Cache-Control headers for CDNs / reverse proxies to cache WordPress pages for a long period of times (days+). As such this plugin also handles invalidations on content updates, to FLUSH the CDN / reverse proxy on page changes. +Smartcache integrates with Batcache to smartly tune the cache lifetime for your content. -This is a work-in-progress. -## Todo +## Behaviour -- Delete post / transition should trigger invalidate. +By default, caching plugins like Batcache will cache for a static 5 minutes for all content. + +Smartcache dynamically tunes this cache lifetime to match the type of content. It breaks content into three buckets: frequently updated, regular content, and infrequently updated content. + +Frequently updated content is cached for 5 minutes. This content is: + +* The "home" page - this is the page showing the list of posts, not necessarily the "front page" for sites using a static home page. +* Content (posts, pages, etc) published in the past 24 hours + +Regular content is cached for 6 hours. This content is: + +* Content published in the past 30 days (except last 24 hours as above) +* Most archive pages (including categories, tags, author pages) +* Date archive pages, except the current one (today/current month/current year) +* Search pages + +Infrequently updated content is cached for 14 days. This content is: + +* Content published more than 30 days ago +* Pages (except those published recently) +* Date archive pages which aren't the current one +* 404 pages + +Smartcache forces cache invalidation on the CDN in the following cases: + +* Publishing a new piece of content (to invalidate the 404) +* Updating an infrequently updated piece of content + + +## Overriding behaviour + +Smartcache has a variety of filters available. These include: + +* `smartcache.old_threshold` - Filter how long a post must be published before it's considered old (infrequently updated). Default is 7 days. +* `smartcache.is_old_post` - Filter whether a specific post is considered old (infrequently updated). (Default true for posts older than the old threshold.) +* `smartcache.is_new_post` - Filter whether a specific post is considered new (frequently updated). (Default true if published in previous 24 hours.) +* `smartcache.max-age` - Filter the maximum lifetime for the current page directly. +* `smartcache.should_cache` - Filter whether a page should be cached at all. (Only affects whether Smartcache generates a header, but may be overridden by other behaviour or by the cache itself.) +* `smartcache.urls_to_invalidate_for_post` - Filter which URLs to invalidate for a given post. +* `smartcache.should_invalidate` - Should we invalidate URLs for this post? (Default true, false for new content as it will expire naturally quickly.) diff --git a/inc/admin/namespace.php b/inc/admin/namespace.php index bb22251..545e63e 100644 --- a/inc/admin/namespace.php +++ b/inc/admin/namespace.php @@ -14,16 +14,16 @@ */ function bootstrap() : void { add_action( 'admin_menu', __NAMESPACE__ . '\\register_admin_page' ); + add_action( 'admin_init', __NAMESPACE__ . '\\register_settings' ); add_action( 'admin_init', __NAMESPACE__ . '\\check_on_invalidate_urls_submit' ); require_once ABSPATH . '/wp-admin/includes/class-wp-list-table.php'; require_once __DIR__ . '/class-log-list-table.php'; } - function register_admin_page() : void { add_submenu_page( - 'options-general.php', + 'tools.php', _x( 'Smartcache', 'settings page title', 'smartcache' ), _x( 'Smartcache', 'settings menu title', 'smartcache' ), 'manage_options', @@ -32,11 +32,67 @@ function register_admin_page() : void { ); } +function register_settings() { + add_settings_section( + 'smartcache-quota', + __( 'Quota', 'smartcache' ), + __NAMESPACE__ . '\\render_quota_section', + 'smartcache' + ); +} + +function render_quota_section() { + $usage = Smartcache\get_invalidation_quota_usage(); + $quota = Smartcache\get_invalidation_quota(); + + $is_warning = $usage >= ( 0.8 * $quota ); + $is_full = $usage >= $quota; + $class = $is_warning ? 'warning' : ( $is_full ? 'error' : '' ); + ?> +
| + Monthly quota usage + | +
+ + + + |
+
|---|
| + Invalidate all URLs + | +
+
+
+ + + + |
+
|---|---|
| + + | ++ + | +