定制 remic/guzzlecache 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

remic/guzzlecache

最新稳定版本:v0.2

Composer 安装命令:

composer require remic/guzzlecache

包简介

Laravel 5 package for caching Guzzle's GET requests.

README 文档

README

#Guzzle Cache Laravel 5 Package

GuzzleCache is a simple wrapper around the GuzzleHttp library, aimed at optimizing API consuming applications by intercepting GET request and storing/retrieving responses from the Laravel's cache engine.

##Installation

Grab the package with composer :


    composer require remic/guzzlecache:~0.2

##Configuration

The GuzzleCache package works both with Laravel 5 and Lumen, but the configuration process is different.

###Laravel

In Laravel, you need to register the packages service provider into your config/app.php configuration file :

    Remic\GuzzleCache\GuzzleCacheServiceProvider::class, 

If you're using facades, add this line to the corresponding section in config/app.php :

    'GuzzleCache'   => Remic\GuzzleCache\Facades\GuzzleCache::class,

GuzzleCache come shipped with a default configuration file, if you wish to override these defaults, you have to publish the configuration file :


    artisan vendor:publish
    

###Lumen

In Lumen, you need to register the package's service provider into the bootstrap/app.php file :

    $app->register(Remic\GuzzleCache\GuzzleCacheServiceProvider::class);

If you wish to use the GuzzleCache facade, first make sure $app->withFacades(); is uncommented in bootstrap/app.php, then add the following class alias :

    class_alias(Remic\GuzzleCache\Facades\GuzzleCache::class, 'GuzzleCache');

In Lumen, the configuration is handled via the .env file at the root of the project. Here are the default values used by GuzzleCache. If you wish to modify these, just copy and paste these to your .env file :


GUZZLECACHE_LIFETIME=60
GUZZLECACHE_STORE=
GUZZLECACHE_PREFIX=guzzlecache_

##Usage

From your L5 application, call:

$client = GuzzleCache::client(['base_url' => 'http://httpbin.org']);

$res = $client->get('/');

echo $res->getStatusCode();

Here, the $client object is an instance of Guzzle client. You can refer to Guzzle Documentation for more details.

###Specifying a custom lifetime

You can specify an optionnal lifetime when requesting a Guzzle client, that will override the defaults set in GuzzleCache config, for all request made with the object :

// Store all the request made with $client for 15 minutes
$client = GuzzleCache::client(['base_url' => 'http://httpbin.org'], 15); 

##License

MIT

统计信息

  • 总下载量: 9.26k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 18
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 17
  • Watchers: 2
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-03-24