APCu vs Redis for single-server caching
Running a single-server setup. For caching computed values (config, rendered fragments, DB result sets), is APCu worth using or should I just use Redis for everything?
APCu advantage is in-process memory, no serialization, no network. Downside is it does not survive FPM worker restarts and is per-process.
APCu is genuinely faster for read-heavy data that rarely changes: config, feature flags, compiled routes. We use a two-level cache: APCu as L1 with a 60s TTL, Redis as L2 with a longer TTL. L1 miss falls through to Redis and backfills APCu.
Laravel cache driver does not support APCu natively but there are community packages. If you want L1/L2, the simplest approach is just wrapping the cache calls manually.
On PHP-FPM each worker process has its own APCu namespace. A cache set in worker A is not visible in worker B. For session-style or user-specific data this breaks things silently. Only use APCu for data that is identical across all workers.
With Swoole the process model is different: workers are long-lived and shared data in APCu persists. Cache invalidation becomes a real problem because you cannot broadcast invalidation across workers easily.
For route cache, config cache, view cache: APCu is a good fit. The data is identical across workers and generated at deploy time. For anything user or session specific: Redis only.