Skip to content

Add PhpFileCacheEngine: entries as PHP files read through OPcache - #28

Merged
byjg merged 1 commit into
masterfrom
7.0
Nov 6, 2026
Merged

byjg merged 1 commit into
masterfrom
7.0

Conversation

@byjg

@byjg byjg commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Summary

New PSR-16 engine PhpFileCacheEngine: each entry is a PHP file (<?php return [...];) read with include, so with OPcache it is read from memory.

  • Scalars and arrays are written as PHP code (nothing to decode), other values serialized.
  • Files are 0600 (an entry can hold secrets, e.g. a cached configuration), written to a temporary file and renamed (never read half written), then invalidated in OPcache.
  • TTL supported (an expired entry is removed when read); no garbage collector or atomic operations.

For entries written once and read on every request, such as byjg/config's cached container: in php-gluo it removes ~300 us of file reads per web request compared with FileSystemCacheEngine. Not for values that change often (each write recompiles the file; OPcache keeps the old one as wasted memory) — see docs/class-php-file-cache-engine.md.

Breaking changes

None.

Test plan

  • PhpFileCacheEngineTest extends CachePSR16Test: the PSR-16 tests of every engine run against it (atomic and garbage-collector tests skipped: not supported), plus values round-trip (strings with quotes/NUL, ints, floats, nested arrays, objects, INF), 0600 permissions, replacement without temporary files left, a foreign file, a missing directory.
  • Full suite OK, Psalm clean.

Each entry is a PHP file (<?php return [...];) read with include: with
OPcache, it is read from memory. Scalars and arrays are written as PHP code,
other values serialized. The files are 0600 (an entry can hold secrets),
written to a temporary file and renamed, and invalidated in OPcache.

For entries written once and read on every request, such as byjg/config's
cached container (~300 us less per web request in php-gluo than
FileSystemCacheEngine). Not for values that change often. It runs the PSR-16
tests of every engine, plus its own.
@byjg
byjg merged commit 7af4a99 into master Nov 6, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant