Skip to content
Web Performance

Caching Expensive Queries the Simple Way

Theo Marsh
1 min read
2,564
Cover photo for “Caching Expensive Queries the Simple Way”

Most caching bugs come from invalidation. This pattern keeps invalidation in one place so it is hard to get wrong.

Reading work aloud is the cheapest editing tool there is. Your ear catches rhythm problems that your eye skips over, especially in long sentences.

remember.php
function quill_remember( string $key, callable $producer, int $ttl = HOUR_IN_SECONDS ) {
	$value = wp_cache_get( $key, 'quill' );
	if ( false !== $value ) {
		return $value;
	}
	$value = $producer();
	wp_cache_set( $key, $value, 'quill', $ttl );
	return $value;
}
PHP UTF-8·LF·9 lines

Good tools disappear. The ones we keep are the ones we stop noticing, because they do exactly what we expect every single time.

We keep a running document of things that went wrong on past projects. It is not a list of failures so much as a list of warnings, and we read it before every kickoff.

Deadlines help, but only when they are real. A deadline that everyone knows will slip is just a date on a calendar.

0
Continue reading

Related posts

All posts
Conversation

Comments · 0

Posting as guest · Sign in