Manual
Resource management
A few database connections, and one cache, shared among thousands of requests.
Introduction#
Swerve::cache() is one PSR-16 cache shared by every worker, read from local memory once a worker has seen a key. A database or API connection, by contrast, is each worker's own: open a few per worker and lend them out with phasync\Util\Pool rather than one per request. See Cache.
Concepts#
- Caching: whose data is it? – A shared cache is safe when its key holds every input the value depends on.
- Connections, pools and limits – A worker needs few database connections. Borrow one for a query or a transaction and give it back.
Guides#
- Cache – Swerve::cache(): one PSR-16 cache for every worker, read from memory in the worker.
Examples#
- All examples of this topic – 13 with their output.
Reference#
Cache– The cache every worker shares, from Swerve::cache(): a PSR-16 cache held by the master process, the least recently used entries evicted past --cache-size.CacheKeyException– A key Swerve::cache can't take: PSR-16 keys are non-empty strings without {}()/@:.Swerve::cache– The cache every worker shares, held by the master process.