BenchmarkContext
class BenchmarkContext
Context object that bundles shared state for benchmark scenarios.
Constants
| KEY_PREFIX |
Key prefix for benchmark-generated cache entries. Matches the pattern used by DoctorContext (_doctor:test:). |
Methods
Create a new benchmark context instance.
Get the cache repository for this context.
Get the underlying store instance.
Get the cache prefix.
Get patterns to match all tag storage structures with a given tag name prefix.
Get patterns to match all cache value keys with a given key prefix.
Get every pattern needed to remove benchmark-owned keys.
Get a value prefixed with the benchmark prefix.
Create a progress bar using the command's output style.
Write a line to output.
Write a blank line to output.
Call another command (with output).
Check memory usage and throw exception if approaching limit.
Perform cleanup of benchmark data.
Details
at line 49
__construct(string $storeName, int $items, int $tagsPerItem, int $heavyTags, Command $command, Factory $cacheManager)
Create a new benchmark context instance.
at line 62
Repository
getStore()
Get the cache repository for this context.
at line 71
RedisStore
getStoreInstance()
Get the underlying store instance.
at line 91
string
getCachePrefix()
Get the cache prefix.
at line 107
array
getTagStoragePatterns(string $tagNamePrefix)
Get patterns to match all tag storage structures with a given tag name prefix.
Returns patterns for both tag modes to ensure complete cleanup regardless of current mode (important for --compare-tag-modes):
- Any mode: {cachePrefix}_any:tag:{tagNamePrefix}*
- All mode: {cachePrefix}_all:tag:{tagNamePrefix}*
at line 130
array
getCacheValuePatterns(string $keyPrefix)
Get patterns to match all cache value keys with a given key prefix.
Returns patterns for both tag modes to ensure complete cleanup regardless of current mode (important for --compare-tag-modes):
- Untagged keys: {cachePrefix}{keyPrefix}* (same in both modes)
- Tagged keys in all mode: {cachePrefix}{xxh128}:{keyPrefix}* (namespaced)
at line 151
array
getCleanupPatterns()
Get every pattern needed to remove benchmark-owned keys.
The all-mode value pattern overlaps tag storage today. The explicit tag patterns keep each key family covered if that value pattern narrows; deleting the overlap is idempotent.
at line 165
string
prefixed(string $value)
Get a value prefixed with the benchmark prefix.
Used for both cache keys and tag names to ensure complete isolation from production data and safe cleanup.
at line 173
ProgressBar
createProgressBar(int $max)
Create a progress bar using the command's output style.
at line 181
void
line(string $message)
Write a line to output.
at line 189
void
newLine(int $count = 1)
Write a blank line to output.
at line 197
int
call(string $command, array $arguments = [])
Call another command (with output).
at line 207
void
checkMemoryUsage()
Check memory usage and throw exception if approaching limit.
at line 231
void
cleanup()
Perform cleanup of benchmark data.
This method uses mode-aware patterns to ensure complete cleanup:
- Flush all tagged items via $store->tags()->flush()
- Clean remaining benchmark values and tag storage across both modes
- Remove benchmark entries from the any-mode tag registry