CachingDetector implements ResourceDetector
Read onlyYes
FinalYes
Decorator that caches resource detection results to a file.
Wraps another detector and caches its results. On subsequent calls, if the cache file exists, it returns the cached resource instead of running detection again. This is useful for expensive detection operations that don't change during runtime.
The cache is serialized using PHP's serialize/unserialize functions.
Example usage:
// Cache default detectors to system temp directory
$detector = new CachingDetector(
new ChainDetector(
new OsDetector(),
new HostDetector(),
new ProcessDetector(),
),
);
// Cache to custom path
$detector = new CachingDetector(
new ChainDetector(...$detectors),
'/var/cache/app/telemetry_resource.cache',
);
Interfaces
- ResourceDetector
- Interface for detecting resource attributes from the environment.
Methods
- __construct() : mixed
- detect() : Resource
- Detect resource attributes from the environment.
Methods
__construct()
public
__construct(ResourceDetector $detector[, string|null $cachePath = null ]) : mixed
Parameters
- $detector : ResourceDetector
- $cachePath : string|null = null
detect()
Detect resource attributes from the environment.
public
detect() : Resource