Laravel: Avoiding cache data-races

Multiple processes hate this!

Bob and Ana don’t get too well

A simple example of a data race is two users editing an article. Imagine Bob retrieves the draft he left writing at 10:00 AM, starts updating it at 10:05, and then stores back his finished article at 11:00 AM.

Invalidate and regenerate

To avoid the newer data being replaced by older data, we need to know if the data on the cache is “fresher” than what we hold right now. In other words, we need to use a timestamp.

  • There is a time, so we will proceed if the data was persisted before the time we invalidated it.

Graphic Designer graduate. Full Stack Web Developer. Retired Tech & Gaming Editor.