1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Configuration\Jms\Configuration\Cache |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/techdivision/import-configuration-jms |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Configuration\Jms\Configuration; |
22
|
|
|
|
23
|
|
|
use JMS\Serializer\Annotation\Type; |
24
|
|
|
use JMS\Serializer\Annotation\SerializedName; |
25
|
|
|
use TechDivision\Import\Utils\CacheTypes; |
26
|
|
|
use TechDivision\Import\ConfigurationInterface; |
27
|
|
|
use TechDivision\Import\Configuration\CacheConfigurationInterface; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The cache configuration implementation. |
31
|
|
|
* |
32
|
|
|
* @author Tim Wagner <[email protected]> |
33
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
34
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
35
|
|
|
* @link https://github.com/techdivision/import-configuration-jms |
36
|
|
|
* @link http://www.techdivision.com |
37
|
|
|
*/ |
38
|
|
|
class Cache implements CacheConfigurationInterface |
39
|
|
|
{ |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* The cache type. |
43
|
|
|
* |
44
|
|
|
* @var string |
45
|
|
|
* @Type("string") |
46
|
|
|
* @SerializedName("type") |
47
|
|
|
*/ |
48
|
|
|
protected $type; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* The cache's TTL (null === cache item NEVER times out). |
52
|
|
|
* |
53
|
|
|
* @var integer |
54
|
|
|
* @Type("integer") |
55
|
|
|
*/ |
56
|
|
|
protected $time = null; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* The event name the listener has to be registered. |
60
|
|
|
* |
61
|
|
|
* @var string |
62
|
|
|
* @Type("boolean") |
63
|
|
|
*/ |
64
|
|
|
protected $enabled = true; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* A reference to the parent configuration instance. |
68
|
|
|
* |
69
|
|
|
* @var \TechDivision\Import\ConfigurationInterface |
70
|
|
|
*/ |
71
|
|
|
protected $configuration; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Return's the cache type |
75
|
|
|
* |
76
|
|
|
* @return string The cache type |
77
|
|
|
*/ |
78
|
|
|
public function getType() |
79
|
|
|
{ |
80
|
|
|
return $this->type; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Return's the flag whether the cache is enabled or not. |
85
|
|
|
* |
86
|
|
|
* The cache type cache.static is ALWAYS enabled, which is necessary e. g. |
87
|
|
|
* for the registration processor that contains the global data. |
88
|
|
|
* |
89
|
|
|
* @return boolean TRUE if the cache is enabled, else FALSE |
90
|
|
|
*/ |
91
|
|
|
public function isEnabled() |
92
|
|
|
{ |
93
|
|
|
return (($this->enabled && $this->configuration->isCacheEnabled()) || $this->type === CacheTypes::TYPE_STATIC); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Return's the cache TTL in seconds. |
98
|
|
|
* |
99
|
|
|
* @return integer The TTL |
100
|
|
|
*/ |
101
|
|
|
public function getTime() |
102
|
|
|
{ |
103
|
|
|
return $this->time; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Set's the reference to the configuration instance. |
108
|
|
|
* |
109
|
|
|
* @param \TechDivision\Import\ConfigurationInterface $configuration The configuration instance |
110
|
|
|
* |
111
|
|
|
* @return void |
112
|
|
|
*/ |
113
|
|
|
public function setConfiguration(ConfigurationInterface $configuration) |
114
|
|
|
{ |
115
|
|
|
$this->configuration = $configuration; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Return's the reference to the configuration instance. |
120
|
|
|
* |
121
|
|
|
* @return \TechDivision\Import\ConfigurationInterface The configuration instance |
122
|
|
|
*/ |
123
|
|
|
public function getConfiguration() |
124
|
|
|
{ |
125
|
|
|
return $this->configuration; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|