opxcore / config-cache-files
The OpxCore config cache file driver.
1.0.4
2021-02-17 13:12 UTC
Requires
- php: ^7.4
- opxcore/config-cache-interface: ^1.0.0
Requires (Dev)
- phpunit/phpunit: ^9.5
README
Installing
composer require opxcore/config-cache-files
Standalone usage:
use OpxCore\Config\ConfigCacheFiles; $configFiles = new ConfigCacheFiles($path);
Usage with container
use OpxCore\Config\Interfaces\ConfigCacheInterface; use OpxCore\Config\ConfigCacheFiles; $container->bind( ConfigCacheInterface::class, ConfigCacheFiles::class, ['path' => $path] ); $configCache = $container->make(ConfigCacheInterface::class); // or $container->bind(ConfigCacheInterface::class, ConfigCacheFiles::class); $configCache = $container->make(ConfigCacheInterface::class, ['path' => $path]);
Where $path
is absolute path to folder with configuration cache files.
Loading config cache
$loaded = $configCache->load($config, $profile)
Loads array of configurations from path given in a constructor. If $profile
is not set driver will search file with
name config.cache
, in other case name will be config.given_profile.cache
. If file exists and not expired (this
option stored inside file) array of configuration will be loaded to $config
variable and true
would be returned as
function return value. In all other cases function returns false
and $config
variable would be not affected.
Saving config cache
$configCache->save($config, $profile, $ttl)
Saves $config
array to file (see loading). $ttl
is time to live for cached data in seconds.