1 | <?php |
||
15 | abstract class BaseAdapter implements StorageInterface { |
||
16 | |||
17 | /** |
||
18 | * @var int value in seconds, how long should the stats array persist in cache |
||
19 | */ |
||
20 | protected $ttl; |
||
21 | |||
22 | /** |
||
23 | * @var string cache key prefix, might be overridden in constructor in the future |
||
24 | */ |
||
25 | protected $cachePrefix = "PaymaxiComponentCircuitBreaker"; |
||
26 | |||
27 | /** |
||
28 | * Configure instance |
||
29 | * |
||
30 | * @param Integer $ttl How long should circuit breaker data persist (between updates) |
||
31 | * @param String $cachePrefix Value has to be string. If empty default cache key prefix is used. |
||
32 | */ |
||
33 | 5 | public function __construct(int $ttl = 3600, string $cachePrefix = null) { |
|
39 | |||
40 | /** |
||
41 | * Loads circuit breaker service status value. |
||
42 | * For example failures count or last retry time. |
||
43 | * Method does not care what are the attribute names. They are not inspected. |
||
44 | * Any string can be passed as service name and attribute name. |
||
45 | * |
||
46 | * @param string $serviceName name of service to load stats for |
||
47 | * @param string $attributeName name of attribute to load |
||
48 | * @return string value stored or '' if value was not found |
||
49 | * |
||
50 | * @throws \Paymaxi\Component\CircuitBreaker\Storage\StorageException if storage error occurs, handler can not be used |
||
51 | */ |
||
52 | 5 | public function loadStatus($serviceName, $attributeName) { |
|
61 | |||
62 | /** |
||
63 | * Saves circuit breaker service status value. |
||
64 | * Method does not care what are the attribute names. They are not inspected. |
||
65 | * Any string can be passed as service name and attribute name, value can be int/string. |
||
66 | * |
||
67 | * Saving in storage is not guaranteed unless flush is set to true. |
||
68 | * Use calls without flush if you know you will update more than one value and you want to |
||
69 | * improve performance of the calls. |
||
70 | * |
||
71 | * @param string $serviceName name of service to load stats for |
||
72 | * @param string $attributeName name of the attribute to load |
||
73 | * @param string $value string value loaded or '' if nothing found |
||
74 | * @param boolean $flush set to true will force immediate save, false does not guaranteed saving at all. |
||
75 | * @return void |
||
76 | * |
||
77 | * @throws \Paymaxi\Component\CircuitBreaker\Storage\StorageException if storage error occurs, handler can not be used |
||
78 | */ |
||
79 | 5 | public function saveStatus($serviceName, $attributeName, $value, $flush = false) { |
|
83 | |||
84 | /** |
||
85 | * Loads item by cache key. |
||
86 | * |
||
87 | * @param string $key |
||
88 | * @return mixed |
||
89 | * |
||
90 | * @throws \Paymaxi\Component\CircuitBreaker\Storage\StorageException if storage error occurs, handler can not be used |
||
91 | */ |
||
92 | abstract protected function load($key); |
||
93 | |||
94 | /** |
||
95 | * Save item in the cache. |
||
96 | * |
||
97 | * @param string $key |
||
98 | * @param string $value |
||
99 | * @param int $ttl |
||
100 | * @return void |
||
101 | * |
||
102 | * @throws \Paymaxi\Component\CircuitBreaker\Storage\StorageException if storage error occurs, handler can not be used |
||
103 | */ |
||
104 | abstract protected function save($key, $value, $ttl); |
||
105 | } |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: