Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cache driver config. #449

Merged
merged 8 commits into from
Jul 5, 2016
Merged

Add cache driver config. #449

merged 8 commits into from
Jul 5, 2016

Conversation

dingdayu
Copy link
Contributor

@dingdayu dingdayu commented Jul 5, 2016

可实现在实例化Application的时候配置AccessToken缓存方式

示例:

        $cache = new RedisCache();

        // 创建 redis 实例
        $redis = new Redis();
        $redis->connect('redis_host', 6379);

        $cache->setRedis($redis);
        $options = [
            'debug'  => false,
            'app_id' => $wechatInfo['app_id'],
            'secret' => $wechatInfo['app_secret'],
            'token'  => $wechatInfo['token'],
            'aes_key' => $wechatInfo['aes_key'], // 可选
            'cache'   => $cache,
        ];

        $wechatApp = new Application($options);

Signed-off-by: dingdayu [email protected]

@overtrue
Copy link
Collaborator

overtrue commented Jul 5, 2016

@dingdayu 需要再加一个配置类型检查,必须实现缓存接口的对象

$this['cache'] = function () {
return new FilesystemCache(sys_get_temp_dir());
};
if (empty($this['config']['cache'])) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use  Doctrine\Common\Cache as CacheInterface;
...
if (empty($this['config']['cache']) || !($this['config']['cache'] instanceof CacheInterface)) 

@dingdayu
Copy link
Contributor Author

dingdayu commented Jul 5, 2016

检测CacheProvider接口不好吗?@overtrue

@overtrue
Copy link
Collaborator

overtrue commented Jul 5, 2016

@dingdayu 不好,万一用户不想用这个库的缓存想自定义怎么办?还是用接口检查,这是接口存在的意义 。

@@ -25,6 +25,7 @@
*/
namespace EasyWeChat\Foundation;

use Doctrine\Common\Cache as CacheInterface;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不存在吧?正确的应该是:Doctrine\Common\Cache\Cache

@dingdayu
Copy link
Contributor Author

dingdayu commented Jul 5, 2016

as 不是别名定义吗?

@overtrue
Copy link
Collaborator

overtrue commented Jul 5, 2016

@dingdayu 前面写错了。。。,是 Cache\Cache,你少写了一层。。。

@dingdayu
Copy link
Contributor Author

dingdayu commented Jul 5, 2016

汗,,发现了。。

Signed-off-by: dingdayu <[email protected]>
$this['cache'] = function () {
return new FilesystemCache(sys_get_temp_dir());
};
if (!empty($this['config']['cache']) && $this['config']['cache'] instanceof CacheInterface) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if 逻辑错误

@dingdayu
Copy link
Contributor Author

dingdayu commented Jul 5, 2016

丢大了,改了判断,没换里面的逻辑。。。

Signed-off-by: dingdayu <[email protected]>
@overtrue overtrue merged commit cab02a5 into w7corp:master Jul 5, 2016
@overtrue overtrue changed the title Add AccessToen Cache Config Add dache driver config. Jul 5, 2016
@overtrue overtrue changed the title Add dache driver config. Add cache driver config. Jul 5, 2016
overtrue added a commit to EasyWeChat/docs that referenced this pull request Jul 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants