In the new Agent.php (Laravel Jetstream 4.1) that uses MobileDetect, specifically the cache set/get functionality seems to be broken.
I modified the retrieveUsingCacheOrResolve function in Agent.php to show cache get results right after set function by adding some error_logs in the tap function call as below:
return tap(call_user_func($callback), function ($value) use ($cacheKey, $key) {
$result = $this->cache->set($cacheKey, $value);
error_log("Cache set for {$key}: {$value} => " . ($result ? 'true' : 'false'));
$cacheItem = $this->cache->get($cacheKey);
error_log("Key: {$key}, cacheItem: " . print_r($cacheItem, true));
$value = $cacheItem->get();
error_log("Cache get for {$key}: {$value}");
});
What I get for output is as follows (I deleted the keys for brevity, but they are different for each value to be stored):
[24-Nov-2023 22:37:01 UTC] Cache set for jetstream.desktop: 1 => true
[24-Nov-2023 22:37:01 UTC] Key: jetstream.desktop, cacheItem: Detection\Cache\CacheItem Object
(
[key:protected] => <truncated>=
[value:protected] => 1
[ttl:protected] =>
)
[24-Nov-2023 22:37:01 UTC] Cache get for jetstream.desktop: 1
[24-Nov-2023 22:37:01 UTC] Cache set for jetstream.platform: Windows => true
[24-Nov-2023 22:37:01 UTC] Key: jetstream.platform, cacheItem: Detection\Cache\CacheItem Object
(
[key:protected] => <truncated>=
[value:protected] => 1
[ttl:protected] =>
)
[24-Nov-2023 22:37:01 UTC] Cache get for jetstream.platform: 1
[24-Nov-2023 22:37:01 UTC] Cache set for jetstream.browser: Edge => true
[24-Nov-2023 22:37:01 UTC] Key: jetstream.browser, cacheItem: Detection\Cache\CacheItem Object
(
[key:protected] => <truncated>=
[value:protected] => 1
[ttl:protected] =>
)
[24-Nov-2023 22:37:01 UTC] Cache get for jetstream.browser: 1
I am using psr/simple-cache 3.0.0 and have no built in PSR module for PHP (as that was actually causing an exception when Agent tried to initialize the cache).
As you can see, even though cache->set is getting the correct value, the cache object always seems to think the value is 1 (true, I presume).
Hence why cache->get always returns 1.
This has only been broken since latest versions of Jetstream that use the MobileDetect package and PSR/simple-cache 3.0.
So from above output, it looks like cache->set is broken, but I can't see why?
I am using:
PHP v8.2.12 laravel/framework v10.33.0 laravel/fortify v1.18.1 laravel/jetstream v4.1.0 livewire/livewire v3.2.1 psr/simple-cache v3.0.0
I was expecting cache->get to return what I had initially input with cache->set.
As you can see from the output, that is not the case, cache->set always seems to set 1 as the value?