AITeky Learn

AiTeky Original Interactive Learning & Practice Intermediate

PHP and Laravel caching: hit rates, stale prices and the stampede every minute

See how a cache with a time limit cuts database queries, why a price can stay wrong until the entry expires, and fix a popular page whose cache expiry sends a rush of identical queries to the database every minute.

A cache keeps the answer to an expensive question so the next ask is fast. In Laravel, Cache::remember does it in one line. A cache brings two new problems with it: the answer may be stale (out of date) when the data changes, and when a popular entry expires, many requests may all rebuild it at the same moment, a cache stampede.

This course models caching with small Python programs you can run in your browser. Python stands in for PHP: the code is not Laravel, but the time-to-live, the staleness and the stampede it shows are the real behaviour of any cache. Check the Laravel documentation for Cache::remember, atomic locks and cache tags. All numbers are made up.

  • Learn lessons explain one idea at a time and let you run it.
  • Industry ready lessons decide and justify, and end with interview questions.

No PHP experience is assumed. Basic Python helps.

Locked. Sign up free

Learn

Understand each idea with everyday examples. No coding background needed.

  1. 01 25 min Free sample 🔒 AiTeky Pass A cache with a time limit Build a small cache with a time-to-live, count how many database queries it saves, and see how the time limit changes the saving.
  2. 02 25 min 🔒 AiTeky Pass The price that stayed old Change a price while it is cached, count how many requests still see the old one, and see how clearing the cache entry on update removes the stale window.

Industry ready

Real problems from real jobs, and the questions interviewers ask about them.

  1. 03 30 min 🔒 AiTeky Pass On the job: the stampede every minute A popular product page's cache expires every minute and a rush of identical queries hits the database. Count the load, compare four fixes by effort and risk, choose, and write the note.

We use essential cookies to run the site. With your permission we also set one anonymous ID to count unique visitors, and analytics cookies to see which pages help learners. Cookie notice

Join AiTeky Learn. It's free.

Create a free account to track your progress, save items for later and get study suggestions.

Sign up free Log in