@@ -24,9 +24,9 @@ class KeyValueCache
2424 protected $ cacheExpirationTime ;
2525
2626 /**
27- * @param CacheManager $cacheManager
27+ * @param CacheManager $cacheManager
2828 */
29- public function __construct ($ cacheManager , \DateInterval | int | null $ ttl = null )
29+ public function __construct ($ cacheManager , \DateInterval | int | null $ ttl = null )
3030 {
3131 $ this ->cacheManager = $ cacheManager ;
3232 $ this ->cacheExpirationTime = $ ttl ?? InspireCmsConfig::get ('cache.key_value.ttl ' ) ?? \DateInterval::createFromDateString ('24 hours ' );
@@ -39,47 +39,46 @@ public function cacheAll(): void
3939 {
4040 $ model = $ this ->attemptRetrieveModel ();
4141
42- if (!$ model ) {
42+ if (! $ model ) {
4343 return ;
4444 }
4545
4646 $ keyValues = $ model ::all ();
47-
47+
4848 foreach ($ keyValues as $ keyValue ) {
4949 $ this ->set ($ keyValue ->key , $ keyValue ->value );
5050 }
5151 }
5252
5353 /**
5454 * Get a value by key from cache or database
55- *
56- * @param string $key
57- * @param mixed $default
55+ *
56+ * @param mixed $default
5857 * @return mixed
5958 */
6059 public function get (string $ key , $ default = null )
6160 {
6261 $ model = $ this ->attemptRetrieveModel ();
6362
64- if (!$ model ) {
63+ if (! $ model ) {
6564 return ;
6665 }
6766
6867 return $ this ->cacheManager ->remember (
6968 $ this ->getCacheKey ($ key ),
70- $ this ->cacheExpirationTime ,
69+ $ this ->cacheExpirationTime ,
7170 function () use ($ key , $ default , $ model ) {
7271 $ keyValue = $ model ::findKeyValue ($ key );
72+
7373 return $ keyValue ? $ keyValue ->value : $ default ;
7474 }
7575 );
7676 }
7777
7878 /**
7979 * Set a value in the cache
80- *
81- * @param string $key
82- * @param mixed $value
80+ *
81+ * @param mixed $value
8382 */
8483 public function set (string $ key , $ value ): void
8584 {
@@ -101,12 +100,12 @@ public function clear(): void
101100 {
102101 $ model = $ this ->attemptRetrieveModel ();
103102
104- if (!$ model ) {
103+ if (! $ model ) {
105104 return ;
106105 }
107106
108107 $ keyValues = $ model ::all ();
109-
108+
110109 foreach ($ keyValues as $ keyValue ) {
111110 $ this ->forget ($ keyValue ->key );
112111 }
@@ -123,7 +122,7 @@ protected function getCacheKey(string $key): string
123122 /**
124123 * @return bool|class-string<Model & KeyValue>
125124 */
126- protected function attemptRetrieveModel (): bool | string
125+ protected function attemptRetrieveModel (): bool | string
127126 {
128127 try {
129128 $ model = InspireCmsConfig::getKeyValueModelClass ();
@@ -140,4 +139,4 @@ protected function attemptRetrieveModel(): bool|string
140139 return false ;
141140 }
142141 }
143- }
142+ }
0 commit comments