I refactored StaleCache today. An older library I made that brings Laravel-style stale cache logic to WordPress.

The original version used a single class with static methods, which never sat right with me. Laravel uses a “facade” system to make its Cache::flexible() syntax work, but porting that whole architecture into a tiny WordPress library felt like overkill.

Today’s approach is simpler: only the get() method is static. It uses a class callback to access the internal methods behind the scenes. Same concept, but less complex.

Testing got an upgrade too. WordPress relies heavily on global function calls, which makes unit testing painful. The previous version used a mess of mocks. The new one uses interfaces and injected classes to handle WordPress hooks and functions indirectly. This makes testing cleaner, at the cost of more interface code than I’d ideally want in a small library.

I’m not a huge fan of this complexity of architecture in what could be a simpler piece of code. But the PHP ecosystem expects it; it makes testing easier, and honestly, it helps AI tools understand the code better too.