1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* This file is part of Phpfastcache. |
5
|
|
|
* |
6
|
|
|
* @license MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files. |
9
|
|
|
* |
10
|
|
|
* @author Georges.L (Geolim4) <[email protected]> |
11
|
|
|
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
declare(strict_types=1); |
15
|
|
|
|
16
|
|
|
namespace Phpfastcache\Drivers\Devrandom; |
17
|
|
|
|
18
|
|
|
use Phpfastcache\Config\ConfigurationOption; |
19
|
|
|
use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException; |
20
|
|
|
use Phpfastcache\Exceptions\PhpfastcacheLogicException; |
21
|
|
|
|
22
|
|
|
class Config extends ConfigurationOption |
23
|
|
|
{ |
24
|
|
|
protected int $dataLength = 16; |
25
|
|
|
|
26
|
|
|
protected int $chanceOfRetrieval = 50; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @return int |
30
|
|
|
*/ |
31
|
|
|
public function getDataLength(): int |
32
|
|
|
{ |
33
|
|
|
return $this->dataLength; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param int $dataLength |
38
|
|
|
* @return Config |
39
|
|
|
* @throws PhpfastcacheLogicException |
40
|
|
|
*/ |
41
|
|
|
public function setDataLength(int $dataLength): Config |
42
|
|
|
{ |
43
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
44
|
|
|
$this->dataLength = $dataLength; |
45
|
|
|
return $this; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return int |
50
|
|
|
*/ |
51
|
|
|
public function getChanceOfRetrieval(): int |
52
|
|
|
{ |
53
|
|
|
return $this->chanceOfRetrieval; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param int $chanceOfRetrieval |
58
|
|
|
* @return Config |
59
|
|
|
* @throws PhpfastcacheInvalidArgumentException |
60
|
|
|
* @throws PhpfastcacheLogicException |
61
|
|
|
*/ |
62
|
|
|
public function setChanceOfRetrieval(int $chanceOfRetrieval): Config |
63
|
|
|
{ |
64
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
65
|
|
|
if ($chanceOfRetrieval < 0 || $chanceOfRetrieval > 100) { |
66
|
|
|
throw new PhpfastcacheInvalidArgumentException('Chance of retrieval must be between 0 and 100'); |
67
|
|
|
} |
68
|
|
|
$this->chanceOfRetrieval = $chanceOfRetrieval; |
69
|
|
|
return $this; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|