Skip to content

Commit 4aa4fe1

Browse files
committed
updaet 2.0
1 parent 4fa9b84 commit 4aa4fe1

File tree

4 files changed

+36
-26
lines changed

4 files changed

+36
-26
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
composer.phar
22
/vendor/
3+
.idea
34

45
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
56
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file

composer.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@
33
"description": "rabbit cache",
44
"type": "library",
55
"require": {
6-
"rabbit/framework": "^1.0",
6+
"php": ">=7.4.0",
7+
"ext-swoole": ">=4.5.0",
8+
"rabbit/base": "dev-master",
9+
"rabbit/parser": "dev-master",
710
"psr/simple-cache": "^1.0.0"
811
},
12+
"require-dev": {
13+
"swoole/ide-helper": "@dev",
14+
"phpunit/phpunit": "*"
15+
},
16+
"suggest": {
17+
"ext-igbinary": "use igbinary serialize"
18+
},
919
"license": "MIT",
1020
"authors": [
1121
{
@@ -15,7 +25,7 @@
1525
],
1626
"autoload": {
1727
"psr-4": {
18-
"rabbit\\cache\\": "src/"
28+
"Rabbit\\Cache\\": "src/"
1929
}
2030
}
2131
}

src/AbstractCache.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?php
2+
declare(strict_types=1);
23

4+
namespace Rabbit\Cache;
35

4-
namespace rabbit\cache;
5-
6-
use rabbit\helper\StringHelper;
6+
use Rabbit\Base\Helper\StringHelper;
7+
use function extension_loaded;
78

89
/**
910
* Class AbstractCache
@@ -14,14 +15,14 @@ class AbstractCache
1415
/**
1516
* @var bool whether [igbinary serialization](https://pecl.php.net/package/igbinary) is available or not.
1617
*/
17-
private $igbinaryAvailable = false;
18+
private bool $igbinaryAvailable = false;
1819

1920
/**
2021
* AbstractCache constructor.
2122
*/
2223
public function __construct()
2324
{
24-
$this->igbinaryAvailable = \extension_loaded('igbinary');
25+
$this->igbinaryAvailable = extension_loaded('igbinary');
2526
}
2627

2728
/**

src/Cache.php

+17-19
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
<?php
2-
/**
3-
* Created by PhpStorm.
4-
* User: Administrator
5-
* Date: 2018/10/24
6-
* Time: 18:00
7-
*/
2+
declare(strict_types=1);
83

9-
namespace rabbit\cache;
4+
namespace Rabbit\Cache;
105

116
use Psr\SimpleCache\CacheInterface;
12-
use rabbit\parser\ParserInterface;
7+
use Psr\SimpleCache\InvalidArgumentException;
8+
use Rabbit\Parser\ParserInterface;
139

1410
/**
1511
* Class Cache
@@ -20,20 +16,22 @@ class Cache implements CacheInterface
2016
/**
2117
* @var string
2218
*/
23-
private $driver = 'memory';
19+
private string $driver = 'memory';
2420

2521
/**
2622
* @var array
2723
*/
28-
private $drivers = [];
24+
private array $drivers = [];
2925

3026
/**
3127
* @var ParserInterface|null
3228
*/
33-
private $serializer = null;
29+
private ?ParserInterface $serializer = null;
3430

3531
/**
3632
* Cache constructor.
33+
* @param array $drivers
34+
* @param ParserInterface|null $serializer
3735
*/
3836
public function __construct(array $drivers, ParserInterface $serializer = null)
3937
{
@@ -62,7 +60,7 @@ public function getDriver(string $driver = null): CacheInterface
6260
* @param int $duration
6361
* @param string $driver
6462
* @return mixed
65-
* @throws \Psr\SimpleCache\InvalidArgumentException
63+
* @throws InvalidArgumentException
6664
*/
6765
public function cache(string $key, callable $function, int $duration = 0, string $driver = 'memory')
6866
{
@@ -87,7 +85,7 @@ private function getDrivers(): array
8785
* @param string $key
8886
* @param null $default
8987
* @return mixed
90-
* @throws \Psr\SimpleCache\InvalidArgumentException
88+
* @throws InvalidArgumentException
9189
*/
9290
public function get($key, $default = null)
9391
{
@@ -99,7 +97,7 @@ public function get($key, $default = null)
9997
* @param mixed $value
10098
* @param null $ttl
10199
* @return bool
102-
* @throws \Psr\SimpleCache\InvalidArgumentException
100+
* @throws InvalidArgumentException
103101
*/
104102
public function set($key, $value, $ttl = null)
105103
{
@@ -109,7 +107,7 @@ public function set($key, $value, $ttl = null)
109107
/**
110108
* @param string $key
111109
* @return bool
112-
* @throws \Psr\SimpleCache\InvalidArgumentException
110+
* @throws InvalidArgumentException
113111
*/
114112
public function delete($key)
115113
{
@@ -128,7 +126,7 @@ public function clear()
128126
* @param iterable $keys
129127
* @param null $default
130128
* @return iterable
131-
* @throws \Psr\SimpleCache\InvalidArgumentException
129+
* @throws InvalidArgumentException
132130
*/
133131
public function getMultiple($keys, $default = null)
134132
{
@@ -139,7 +137,7 @@ public function getMultiple($keys, $default = null)
139137
* @param iterable $values
140138
* @param null $ttl
141139
* @return bool
142-
* @throws \Psr\SimpleCache\InvalidArgumentException
140+
* @throws InvalidArgumentException
143141
*/
144142
public function setMultiple($values, $ttl = null)
145143
{
@@ -149,7 +147,7 @@ public function setMultiple($values, $ttl = null)
149147
/**
150148
* @param iterable $keys
151149
* @return bool
152-
* @throws \Psr\SimpleCache\InvalidArgumentException
150+
* @throws InvalidArgumentException
153151
*/
154152
public function deleteMultiple($keys)
155153
{
@@ -159,7 +157,7 @@ public function deleteMultiple($keys)
159157
/**
160158
* @param string $key
161159
* @return bool
162-
* @throws \Psr\SimpleCache\InvalidArgumentException
160+
* @throws InvalidArgumentException
163161
*/
164162
public function has($key)
165163
{

0 commit comments

Comments
 (0)