1
|
|
|
<?php namespace Comodojo\Cache\Providers; |
2
|
|
|
|
3
|
|
|
use \Comodojo\Cache\Drivers\Apc as ApcDriver; |
4
|
|
|
use \Comodojo\Cache\Item; |
5
|
|
|
use \Comodojo\Cache\Components\EnhancedCacheItemPoolStats; |
6
|
|
|
use \Psr\Log\LoggerInterface; |
7
|
|
|
use \Comodojo\Exception\CacheException; |
8
|
|
|
use \Exception; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Apcu provider |
12
|
|
|
* |
13
|
|
|
* @package Comodojo Spare Parts |
14
|
|
|
* @author Marco Giovinazzi <[email protected]> |
15
|
|
|
* @license MIT |
16
|
|
|
* |
17
|
|
|
* LICENSE: |
18
|
|
|
* |
19
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
20
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
21
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
22
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
23
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
24
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
25
|
|
|
* THE SOFTWARE. |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
View Code Duplication |
class Apc extends AbstractEnhancedProvider { |
|
|
|
|
29
|
|
|
|
30
|
52 |
|
public function __construct(LoggerInterface $logger = null) { |
31
|
|
|
|
32
|
|
|
try { |
33
|
|
|
|
34
|
52 |
|
$this->driver = new ApcDriver(); |
35
|
|
|
|
36
|
52 |
|
parent::__construct($logger); |
37
|
|
|
|
38
|
|
|
} catch (Exception $e) { |
39
|
|
|
|
40
|
|
|
throw new CacheException($e->getMessage()); |
41
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
52 |
|
} |
45
|
|
|
|
46
|
2 |
|
public function getStats() { |
47
|
|
|
|
48
|
2 |
|
$info = $this->driver->stats(); |
49
|
|
|
|
50
|
2 |
|
$entries = isset($info['num_entries']) ? $info['num_entries'] : null; |
51
|
|
|
|
52
|
2 |
|
return new EnhancedCacheItemPoolStats( |
53
|
2 |
|
$this->getId(), |
54
|
2 |
|
$this->driver->getName(), |
55
|
2 |
|
$this->getState(), |
56
|
|
|
$entries, |
57
|
|
|
$info |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.