@@ -23,15 +23,15 @@ |
||
| 23 | 23 | echo "Cache Found: "; |
| 24 | 24 | print_r($Cacheer->getCache($cacheKey)); |
| 25 | 25 | } else { |
| 26 | - echo $Cacheer->getMessage(); |
|
| 26 | + echo $Cacheer->getMessage(); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | // Renovando os dados do cache |
| 30 | 30 | $Cacheer->renewCache($cacheKey, 3600); |
| 31 | 31 | |
| 32 | 32 | if($Cacheer->isSuccess()){ |
| 33 | - echo $Cacheer->getMessage() . PHP_EOL; |
|
| 33 | + echo $Cacheer->getMessage() . PHP_EOL; |
|
| 34 | 34 | } else { |
| 35 | - echo $Cacheer->getMessage() . PHP_EOL; |
|
| 35 | + echo $Cacheer->getMessage() . PHP_EOL; |
|
| 36 | 36 | |
| 37 | 37 | } |
| 38 | 38 | \ No newline at end of file |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | $Cacheer->putCache($cacheKey, $userProfile, ttl: 300); |
| 20 | 20 | |
| 21 | 21 | // Recuperando dados do cache |
| 22 | -if($Cacheer->isSuccess()){ |
|
| 22 | +if ($Cacheer->isSuccess()) { |
|
| 23 | 23 | echo "Cache Found: "; |
| 24 | 24 | print_r($Cacheer->getCache($cacheKey)); |
| 25 | 25 | } else { |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | // Renovando os dados do cache |
| 30 | 30 | $Cacheer->renewCache($cacheKey, 3600); |
| 31 | 31 | |
| 32 | -if($Cacheer->isSuccess()){ |
|
| 32 | +if ($Cacheer->isSuccess()) { |
|
| 33 | 33 | echo $Cacheer->getMessage() . PHP_EOL; |
| 34 | 34 | } else { |
| 35 | 35 | echo $Cacheer->getMessage() . PHP_EOL; |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | echo "Cache Found: "; |
| 30 | 30 | print_r($Cacheer->getCache($cacheKey)); |
| 31 | 31 | } else { |
| 32 | - echo $Cacheer->getMessage(); |
|
| 32 | + echo $Cacheer->getMessage(); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | |
@@ -40,6 +40,6 @@ discard block |
||
| 40 | 40 | echo $Cacheer->getMessage() . PHP_EOL; |
| 41 | 41 | print_r($Cacheer->getCache($cacheKey)); |
| 42 | 42 | } else { |
| 43 | - echo $Cacheer->getMessage(); |
|
| 43 | + echo $Cacheer->getMessage(); |
|
| 44 | 44 | } |
| 45 | 45 | |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | $Cacheer->putCache($cacheKey, $userProfile); |
| 26 | 26 | |
| 27 | 27 | // Recuperando dados do cache |
| 28 | -if($Cacheer->isSuccess()){ |
|
| 28 | +if ($Cacheer->isSuccess()) { |
|
| 29 | 29 | echo "Cache Found: "; |
| 30 | 30 | print_r($Cacheer->getCache($cacheKey)); |
| 31 | 31 | } else { |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | // Mesclando os dados |
| 37 | 37 | $Cacheer->appendCache($cacheKey, $userProfile02); |
| 38 | 38 | |
| 39 | -if($Cacheer->isSuccess()){ |
|
| 39 | +if ($Cacheer->isSuccess()) { |
|
| 40 | 40 | echo $Cacheer->getMessage() . PHP_EOL; |
| 41 | 41 | print_r($Cacheer->getCache($cacheKey)); |
| 42 | 42 | } else { |
@@ -12,20 +12,20 @@ discard block |
||
| 12 | 12 | class CacheRedisHelper |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @param mixed $data |
|
| 17 | - * @param bool $serialize |
|
| 18 | - * @return string |
|
| 19 | - */ |
|
| 20 | - public static function serialize(mixed $data, bool $serialize = true) |
|
| 21 | - { |
|
| 15 | + /** |
|
| 16 | + * @param mixed $data |
|
| 17 | + * @param bool $serialize |
|
| 18 | + * @return string |
|
| 19 | + */ |
|
| 20 | + public static function serialize(mixed $data, bool $serialize = true) |
|
| 21 | + { |
|
| 22 | 22 | if($serialize) { |
| 23 | - return serialize($data); |
|
| 23 | + return serialize($data); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | return unserialize($data); |
| 27 | 27 | |
| 28 | - } |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * @param array $item |
@@ -54,63 +54,63 @@ discard block |
||
| 54 | 54 | return (array)$cacheData; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @param mixed $currentCacheData |
|
| 59 | - * @param mixed $cacheData |
|
| 60 | - * @return array |
|
| 61 | - */ |
|
| 62 | - public static function arrayIdentifier(mixed $currentCacheData, mixed $cacheData) |
|
| 63 | - { |
|
| 64 | - /** |
|
| 65 | - * Se ambos forem arrays, mescle-os de forma recursiva para preservar subarrays |
|
| 66 | - */ |
|
| 67 | - if (is_array($currentCacheData) && is_array($cacheData)) { |
|
| 68 | - return self::mergeRecursive($currentCacheData, $cacheData); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Se $currentCacheData não for um array, inicialize-o como um array vazio |
|
| 73 | - */ |
|
| 74 | - if (!is_array($currentCacheData)) { |
|
| 75 | - $currentCacheData = []; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Se $cacheData não for um array, converta-o em um array |
|
| 80 | - */ |
|
| 81 | - if (!is_array($cacheData)) { |
|
| 82 | - $cacheData = [$cacheData]; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - return array_merge($currentCacheData, $cacheData); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Mescla arrays de forma recursiva. |
|
| 90 | - * @param array $array1 |
|
| 91 | - * @param array $array2 |
|
| 92 | - * @return array |
|
| 93 | - */ |
|
| 94 | - private static function mergeRecursive(array $array1, array $array2) |
|
| 95 | - { |
|
| 96 | - foreach ($array2 as $key => $value) { |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Se a chave existe em ambos os arrays e ambos os valores são arrays, mescle recursivamente |
|
| 100 | - */ |
|
| 101 | - if (isset($array1[$key]) && is_array($array1[$key]) && is_array($value)) { |
|
| 102 | - $array1[$key] = self::mergeRecursive($array1[$key], $value); |
|
| 103 | - } else { |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Caso contrário, sobrescreva o valor em $array1 com o valor de $array2 |
|
| 107 | - */ |
|
| 108 | - $array1[$key] = $value; |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - return $array1; |
|
| 113 | - } |
|
| 57 | + /** |
|
| 58 | + * @param mixed $currentCacheData |
|
| 59 | + * @param mixed $cacheData |
|
| 60 | + * @return array |
|
| 61 | + */ |
|
| 62 | + public static function arrayIdentifier(mixed $currentCacheData, mixed $cacheData) |
|
| 63 | + { |
|
| 64 | + /** |
|
| 65 | + * Se ambos forem arrays, mescle-os de forma recursiva para preservar subarrays |
|
| 66 | + */ |
|
| 67 | + if (is_array($currentCacheData) && is_array($cacheData)) { |
|
| 68 | + return self::mergeRecursive($currentCacheData, $cacheData); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Se $currentCacheData não for um array, inicialize-o como um array vazio |
|
| 73 | + */ |
|
| 74 | + if (!is_array($currentCacheData)) { |
|
| 75 | + $currentCacheData = []; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Se $cacheData não for um array, converta-o em um array |
|
| 80 | + */ |
|
| 81 | + if (!is_array($cacheData)) { |
|
| 82 | + $cacheData = [$cacheData]; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + return array_merge($currentCacheData, $cacheData); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Mescla arrays de forma recursiva. |
|
| 90 | + * @param array $array1 |
|
| 91 | + * @param array $array2 |
|
| 92 | + * @return array |
|
| 93 | + */ |
|
| 94 | + private static function mergeRecursive(array $array1, array $array2) |
|
| 95 | + { |
|
| 96 | + foreach ($array2 as $key => $value) { |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Se a chave existe em ambos os arrays e ambos os valores são arrays, mescle recursivamente |
|
| 100 | + */ |
|
| 101 | + if (isset($array1[$key]) && is_array($array1[$key]) && is_array($value)) { |
|
| 102 | + $array1[$key] = self::mergeRecursive($array1[$key], $value); |
|
| 103 | + } else { |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Caso contrário, sobrescreva o valor em $array1 com o valor de $array2 |
|
| 107 | + */ |
|
| 108 | + $array1[$key] = $value; |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + return $array1; |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | 115 | } |
| 116 | 116 | |