Understanding re-entrancy and cache I/O
masterThe removeTokensCached function runs inside an active MutatingWrapper::stream_open callback. Because performing file I/O inside this callback would cause infinite recursion, the library uses a specific re-entrancy pattern.
The Re-entrancy Pattern:
All cache reads and writes must be wrapped in a single stream_wrapper_restore(...) ... finally { unregister + re-register MutatingWrapper } block. Warning: Attempting multiple stream_wrapper_restore cycles within a single callback can corrupt PHP's internal stream-wrapper state.
Cache Details:
- Keys: Cache files are keyed by
sha1(code + tokens + CacheVersion + PHP major.minor version). - Atomicity: Cache writes are performed atomically using a temporary file and
renameto prevent corruption from concurrent writers or interrupted processes. - Upgrades: If you modify the token-removal algorithm, you must increment
CacheVersionto prevent stale caches from persisting.