Skip to content

Commit d4928b7

Browse files
committed
Fix cache ttl.
1 parent f0ff8dc commit d4928b7

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

src/CacheBridge.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the overtrue/laravel-wechat.
5+
*
6+
* (c) overtrue <[email protected]>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Overtrue\LaravelWeChat;
13+
14+
use Illuminate\Cache\Repository;
15+
use Psr\SimpleCache\CacheInterface;
16+
17+
class CacheBridge implements CacheInterface
18+
{
19+
/**
20+
* @var \Illuminate\Cache\Repository
21+
*/
22+
protected $repository;
23+
24+
/**
25+
* @param \Illuminate\Cache\Repository $repository
26+
*/
27+
public function __construct(Repository $repository)
28+
{
29+
$this->repository = $repository;
30+
}
31+
32+
public function get($key, $default = null)
33+
{
34+
return $this->repository->get($key, $default);
35+
}
36+
37+
public function set($key, $value, $ttl = null)
38+
{
39+
return $this->repository->set($key, $value, $this->toMinutes($ttl));
40+
}
41+
42+
public function delete($key)
43+
{
44+
}
45+
46+
public function clear()
47+
{
48+
}
49+
50+
public function getMultiple($keys, $default = null)
51+
{
52+
}
53+
54+
public function setMultiple($values, $ttl = null)
55+
{
56+
}
57+
58+
public function deleteMultiple($keys)
59+
{
60+
}
61+
62+
public function has($key)
63+
{
64+
return $this->repository->has($key);
65+
}
66+
67+
protected function toMinutes($ttl = null)
68+
{
69+
if (!is_null($ttl)) {
70+
return $ttl / 60;
71+
}
72+
}
73+
}

src/ServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function register()
8383
$this->app->singleton($class, function ($laravelApp) use ($name, $class) {
8484
$app = new $class(array_merge(config('wechat.defaults', []), config('wechat.'.$name)));
8585
if (config('wechat.defaults.use_laravel_cache')) {
86-
$app['cache'] = $laravelApp['cache.store'];
86+
$app['cache'] = new CacheBridge($laravelApp['cache.store']);
8787
}
8888
$app['request'] = $laravelApp['request'];
8989

0 commit comments

Comments
 (0)