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 the current tag mode.
Check if the store is configured for 'any' tag mode.
Check if the store is configured for 'all' tag mode.
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 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 64
Repository
getStore()
Get the cache repository for this context.
at line 73
RedisStore
getStoreInstance()
Get the underlying store instance.
at line 93
string
getCachePrefix()
Get the cache prefix.
at line 101
TagMode
getTagMode()
Get the current tag mode.
at line 109
bool
isAnyMode()
Check if the store is configured for 'any' tag mode.
at line 117
bool
isAllMode()
Check if the store is configured for 'all' tag mode.
at line 133
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 156
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 174
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 182
ProgressBar
createProgressBar(int $max)
Create a progress bar using the command's output style.
at line 190
void
line(string $message)
Write a line to output.
at line 198
void
newLine(int $count = 1)
Write a blank line to output.
at line 206
int
call(string $command, array $arguments = [])
Call another command (with output).
at line 216
void
checkMemoryUsage()
Check memory usage and throw exception if approaching limit.
at line 241
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 non-tagged benchmark keys
- Clean any remaining tag storage structures (matching _bench: prefix)
- Run prune command to clean up orphans