urbanindo / yii2-s3cache
Yii2 S3缓存组件
1.1.0
2017-05-31 04:36 UTC
Requires
- php: >=5.5.0
- aws/aws-sdk-php: ^3.28.0
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-09-22 16:45:19 UTC
README
基于AWS简单存储服务的文件缓存组件用于Yii2
适用于大型且长期存在的对象。
要求
- PHP >= 5.5
- AWS SDK >= 3.28.0
安装
安装此扩展的首选方式是通过Composer。
运行以下命令:
php composer.phar require --prefer-dist urbanindo/yii2-s3cache "*"
或添加以下内容到您的composer.json文件的require部分:
"urbanindo/yii2-s3cache": "*"
设置
在配置中添加组件。
'components' => [ 's3Cache' => [ 'class' => 'UrbanIndo\Yii2\S3Cache\Cache', 'bucket' => 'mybucket', 'cachePrefix' => '123456', 'config' => [ 'key' => 'AKIA1234567890123456', 'secret' => '1234567890123456789012345678901234567890', 'region' => 'ap-southeast-1', ], ] ]
使用
这与常规的数据缓存类似。
$cache = Yii::$app->get('s3Cache'); // try retrieving $data from cache $data = $cache->get($key); if ($data === false) { // $data is not found in cache, calculate it from scratch // store $data in cache so that it can be retrieved next time $cache->set($key, $data); } // $data is available here