2017 © Pedro Peláez
 

library eva-cache

Cache Module of EvaEngine

image

evaengine/eva-cache

Cache Module of EvaEngine

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

EvaCache

通用缓存模块,目前实现了 HTTPRequest 的缓存。, (*1)

HTTPRequest/CacheService

本缓存服务对 phalcon/incubator 进行了二次封装,可以在尽可能少地修改原来的代码 的情况下对 curl 操作加上缓存。, (*2)

示例代码:, (*3)


use Eva\EvaCache\CacheManager; $cacheManager = new CacheManager($this->getDI()->getGlobalCache()); $quotes = $cacheManager->http( function (ProviderInterface $provider) use ($self) { $provider->setBaseUri('http://api.markets.wallstreetcn.com/v1/'); try { $response = $provider->get('quotes.json'); } catch (\Exception $e) { return array(); } if ($response->header->statusCode != 200) { return array(); } return json_decode($response->body); }, 120 // 缓存有效期,单位是秒 ); if (!$quotes) { return $this->view->setVar('quotes', array()); } $quotes = $quotes->results;

以下是使用 HTTPRequest/CacheService 之前的代码:, (*4)

$quotes = array();
$provider  = Request::getProvider();
$provider->setBaseUri('http://api.markets.wallstreetcn.com/v1/');
try {
    $response = $provider->get('quotes.json');
} catch (\Exception $e) {
    return $this->view->setVar('quotes', array());
}
if($response->header->statusCode != 200) {
    return $this->view->setVar('quotes', array());
}
$quotes = json_decode($response->body);
$quotes = $quotes->results;

The Versions

23/04 2015

dev-master

9999999-dev

Cache Module of EvaEngine

  Sources   Download

BSD-3-Clause

The Requires