opxcore/config-cache-files

OpxCore 配置缓存文件驱动程序。

1.0.4 2021-02-17 13:12 UTC

This package is auto-updated.

Last update: 2024-09-17 21:46:52 UTC


README

Build Status Coverage Status Latest Stable Version Total Downloads License

安装

composer require opxcore/config-cache-files

独立使用

use OpxCore\Config\ConfigCacheFiles;

$configFiles = new ConfigCacheFiles($path);

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]);

其中 $path 是配置缓存文件夹的绝对路径。

加载配置缓存

$loaded = $configCache->load($config, $profile)

从构造函数中给出的路径加载配置数组。如果未设置 $profile,则驱动程序将搜索名为 config.cache 的文件,否则名称将为 config.given_profile.cache。如果文件存在且未过期(此选项存储在文件中),配置数组将加载到 $config 变量中,函数返回值将为 true。在所有其他情况下,函数返回 false,并且 $config 变量将不受影响。

保存配置缓存

$configCache->save($config, $profile, $ttl)

$config 数组保存到文件(见加载)。$ttl 是缓存数据的存活时间(以秒为单位)。