Skip to content

Commit

Permalink
more detailed cache key. (#1028)
Browse files Browse the repository at this point in the history
* more detailed cache key.

* sprintf
  • Loading branch information
mingyoung authored and overtrue committed Nov 15, 2017
1 parent 6dccddc commit 062a5a6
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 9 deletions.
7 changes: 1 addition & 6 deletions src/BasicService/Jssdk/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ class Client extends BaseClient
*/
protected $url;

/**
* Ticket cache prefix.
*/
const TICKET_CACHE_PREFIX = 'easywechat.basic_service.jssdk.ticket.';

/**
* Get config json for jsapi.
*
Expand Down Expand Up @@ -82,7 +77,7 @@ public function getConfigArray(array $apis, bool $debug = false, bool $beta = fa
*/
public function getTicket(bool $refresh = false, string $type = 'jsapi'): array
{
$cacheKey = self::TICKET_CACHE_PREFIX.$this->getAppId();
$cacheKey = sprintf('easywechat.basic_service.jssdk.ticket.%s.%s', $type, $this->getAppId());

if (!$refresh && $this->getCache()->has($cacheKey)) {
return $this->getCache()->get($cacheKey);
Expand Down
2 changes: 1 addition & 1 deletion tests/BasicService/Jssdk/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function testGetTicket()
'ticket' => 'mock-ticket',
'expires_in' => 7200,
];
$cacheKey = Client::TICKET_CACHE_PREFIX.'123456';
$cacheKey = 'easywechat.basic_service.jssdk.ticket.jsapi.123456';
$client->allows()->getCache()->andReturn($cache);

// no refresh and cached
Expand Down
3 changes: 1 addition & 2 deletions tests/OfficialAccount/Card/JssdkClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace EasyWeChat\Tests\OfficialAccount\Card;

use EasyWeChat\BasicService\Jssdk\Client;
use EasyWeChat\Kernel\ServiceContainer;
use EasyWeChat\OfficialAccount\Card\JssdkClient;
use EasyWeChat\Tests\TestCase;
Expand All @@ -29,7 +28,7 @@ public function testGetTicket()
'ticket' => 'mock-ticket',
'expires_in' => 7200,
];
$cacheKey = Client::TICKET_CACHE_PREFIX.'123456';
$cacheKey = 'easywechat.basic_service.jssdk.ticket.wx_card.123456';
$client->allows()->getCache()->andReturn($cache);

$response = new \EasyWeChat\Kernel\Http\Response(200, [], json_encode($ticket));
Expand Down

0 comments on commit 062a5a6

Please sign in to comment.