You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$cache->getOrSet('key3', fn() => 'value3', Ttl::forever()->toSeconds()); // No expiration
140
+
141
+
Use `isForever()` to check if a TTL represents "forever" (i.e., no expiration). It returns true when the TTL value is null.
142
+
143
+
```php
144
+
if (Ttl::from(null)->isForever()) {
145
+
// No expiration
146
+
}
147
+
````
148
+
149
+
### Accessing TTL Value
150
+
151
+
Use `toSeconds()` to get the TTL in seconds (`int`) or `null` for "forever". The public `$value` property can be accessed directly (e.g., `Ttl::seconds(30)->value`), but `toSeconds()` is preferred for clarity.
152
+
153
+
```php
154
+
$ttl = Ttl::seconds(60);
155
+
$seconds = $ttl->toSeconds(); // Returns 60
156
+
$seconds = $ttl->value; // Also 60
157
+
```
158
+
159
+
### Invalid TTL values
160
+
161
+
```php
162
+
$ttl = Ttl::from('abc'); // Converts to 0 (expired)
163
+
$ttl = Ttl::from(1.5); // TypeError: invalid TTL type
0 commit comments