1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* m'Manager | Invoices Management System |
4
|
|
|
* |
5
|
|
|
* This content is released under the Proprietary License (Proprietary) |
6
|
|
|
* |
7
|
|
|
* Copyright (c) 2017, Eric Claver AKAFFOU - All Rights Reserved |
8
|
|
|
* Unauthorized copying of this file, via any medium is strictly prohibited |
9
|
|
|
* Proprietary and confidential |
10
|
|
|
* |
11
|
|
|
* @package m'Manager |
12
|
|
|
* @author Eric Claver AKAFFOU |
13
|
|
|
* @copyright Copyright (c) 2017, on'Eric Computing, Inc. (https://www.onericcomputing.com/) |
14
|
|
|
* @license https://www.mmanager.fr Proprietary License |
15
|
|
|
* @link https://codecanyon.net/item/mmanager-invoices-management-system/19866435?s_rank=1 |
16
|
|
|
* @since Version 1.0.0 |
17
|
|
|
* @filesource |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Mmanager\Persistence\Adapter\CodeIgniter; |
21
|
|
|
|
22
|
|
|
use Mmanager\Contract\CacheInterface; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Abstract Repository Class |
26
|
|
|
*/ |
27
|
|
|
class Cache implements CacheInterface { |
28
|
|
|
protected $CI; |
29
|
|
|
public function __construct() { |
30
|
|
|
$this->CI = & get_instance(); |
31
|
|
|
$this->CI->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file')); |
32
|
|
|
} |
33
|
|
|
public function get($key, $default = null) { |
34
|
|
|
return $this->CI->cache->get($key); |
35
|
|
|
} |
36
|
|
|
public function set($key, $value, $ttl = 604800) { |
37
|
|
|
return $this->CI->cache->save($key, $value, $ttl); |
38
|
|
|
} |
39
|
|
|
public function delete($key) { |
40
|
|
|
return $this->CI->cache->delete($key); |
41
|
|
|
} |
42
|
|
|
public function clear() { |
43
|
|
|
return $this->CI->cache->clean(); |
44
|
|
|
} |
45
|
|
View Code Duplication |
public function getMultiple($keys, $default = null) { |
|
|
|
|
46
|
|
|
$return = []; |
47
|
|
|
is_array($keys) OR $keys = array($keys); |
48
|
|
|
foreach ($keys as &$value) { |
49
|
|
|
array_push($return, $this->get($value)); |
50
|
|
|
} |
51
|
|
|
unset($value); |
52
|
|
|
return $return; |
|
|
|
|
53
|
|
|
} |
54
|
|
View Code Duplication |
public function setMultiple($values, $ttl = 604800) { |
|
|
|
|
55
|
|
|
$return = []; |
56
|
|
|
is_array($keys) OR $keys = array($keys); |
|
|
|
|
57
|
|
|
foreach ($keys as &$value) { |
|
|
|
|
58
|
|
|
array_push($return, $this->set($value, $ttl)); |
59
|
|
|
} |
60
|
|
|
unset($value); |
61
|
|
|
return $return; |
|
|
|
|
62
|
|
|
} |
63
|
|
|
public function deleteMultiple($keys) { |
64
|
|
|
return []; |
|
|
|
|
65
|
|
|
} |
66
|
|
|
public function has($key) { |
67
|
|
|
return $this->CI->cache->get($key); |
68
|
|
|
} |
69
|
|
|
public function cacheInfo() { |
70
|
|
|
return $this->CI->cache->cache_info($type = 'user'); |
71
|
|
|
} |
72
|
|
|
} |
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.