Automattic / Automattic/wp-super-cache

Mark cache files as expired instead of removing

Open
#910 2 comments 0 reactions 0 assignees View on GitHub
[Plugin] Super Cache enhancement
Dominant language
PHP
Stars
436
Forks
130
Avg merge
15h 11m
Merged PRs (30d)
10

Description

I have a website with very dynamic content (2-8 posts and hundreds of comments per hour) and high load. I need to clear all cache on post publish/update and use low cache timeout (like 5 minutes) to make sure that public content is not outdated (too much). With traffic at level of 30 RPS removing cache is freezing website for 10-50 seconds. It is mostly because many concurrent requests try to generate the same page, which drains CPU of my server. We could really avoid this if we just mark cache file as expired instead of removing it, and reuse its content for concurrent requests. Then only first request will regenerate page and all concurrent request may serve old content meantime.

This could be really simple if plugin will use mtime to store timeout for cache file and check it before using the cache. If cache is expired (`filemtime($filePath) < time()`), touch it by `touch($filePath, time() + 10)` and continue generate fresh page. Meantime all concurrent requests will use old cache for 10 seconds (or till new cache will be generated by first request). When new cache file is generated, we touch it by `touch($filePath, time() + $cacheDuration)` - then it will be valid for next `$cacheDuration` seconds.

This should really reduce load spikes for big sites.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.