1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
5
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
6
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
7
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
8
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
9
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
10
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
11
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
12
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
13
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
14
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
15
|
|
|
* |
16
|
|
|
* This software consists of voluntary contributions made by many individuals |
17
|
|
|
* and is licensed under the MIT license. For more information, see |
18
|
|
|
* <http://www.doctrine-project.org>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace Doctrine\ORM\Cache; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Cache regions configuration |
25
|
|
|
* |
26
|
|
|
* @since 2.5 |
27
|
|
|
* @author Fabio B. Silva <[email protected]> |
28
|
|
|
*/ |
29
|
|
|
class RegionsConfiguration |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @var array |
33
|
|
|
*/ |
34
|
|
|
private $lifetimes = []; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var array |
38
|
|
|
*/ |
39
|
|
|
private $lockLifetimes = []; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var integer |
43
|
|
|
*/ |
44
|
|
|
private $defaultLifetime; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var integer |
48
|
|
|
*/ |
49
|
|
|
private $defaultLockLifetime; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param integer $defaultLifetime |
53
|
|
|
* @param integer $defaultLockLifetime |
54
|
|
|
*/ |
55
|
286 |
|
public function __construct($defaultLifetime = 3600, $defaultLockLifetime = 60) |
56
|
|
|
{ |
57
|
286 |
|
$this->defaultLifetime = (integer) $defaultLifetime; |
58
|
286 |
|
$this->defaultLockLifetime = (integer) $defaultLockLifetime; |
59
|
286 |
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return integer |
63
|
|
|
*/ |
64
|
|
|
public function getDefaultLifetime() |
65
|
|
|
{ |
66
|
|
|
return $this->defaultLifetime; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param integer $defaultLifetime |
71
|
|
|
*/ |
72
|
113 |
|
public function setDefaultLifetime($defaultLifetime) |
73
|
|
|
{ |
74
|
113 |
|
$this->defaultLifetime = (integer) $defaultLifetime; |
75
|
113 |
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return integer |
79
|
|
|
*/ |
80
|
|
|
public function getDefaultLockLifetime() |
81
|
|
|
{ |
82
|
|
|
return $this->defaultLockLifetime; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param integer $defaultLockLifetime |
87
|
|
|
*/ |
88
|
|
|
public function setDefaultLockLifetime($defaultLockLifetime) |
89
|
|
|
{ |
90
|
|
|
$this->defaultLockLifetime = (integer) $defaultLockLifetime; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param string $regionName |
95
|
|
|
* |
96
|
|
|
* @return integer |
97
|
|
|
*/ |
98
|
238 |
|
public function getLifetime($regionName) |
99
|
|
|
{ |
100
|
238 |
|
return isset($this->lifetimes[$regionName]) |
101
|
|
|
? $this->lifetimes[$regionName] |
102
|
238 |
|
: $this->defaultLifetime; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param string $name |
107
|
|
|
* @param integer $lifetime |
108
|
|
|
*/ |
109
|
|
|
public function setLifetime($name, $lifetime) |
110
|
|
|
{ |
111
|
|
|
$this->lifetimes[$name] = (integer) $lifetime; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param string $regionName |
116
|
|
|
* |
117
|
|
|
* @return integer |
118
|
|
|
*/ |
119
|
|
|
public function getLockLifetime($regionName) |
120
|
|
|
{ |
121
|
|
|
return isset($this->lockLifetimes[$regionName]) |
122
|
|
|
? $this->lockLifetimes[$regionName] |
123
|
|
|
: $this->defaultLockLifetime; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @param string $name |
128
|
|
|
* @param integer $lifetime |
129
|
|
|
*/ |
130
|
|
|
public function setLockLifetime($name, $lifetime) |
131
|
|
|
{ |
132
|
|
|
$this->lockLifetimes[$name] = (integer) $lifetime; |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|