Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Aug 6, 2018. It is now read-only.

EvaEngine/EvaCache

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

EvaCache

通用缓存模块,目前实现了 HTTPRequest 的缓存。

HTTPRequest/CacheService

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

示例代码:

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 之前的代码:

$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;

About

[READ ONLY] Subtree split of the EvaEngine EvaCache component (see EvaEngine/EvaEngine)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.