|
3 | 3 | namespace Laravel\Jetstream; |
4 | 4 |
|
5 | 5 | use Closure; |
6 | | -use Detection\Cache\CacheException; |
7 | | -use Detection\Exception\MobileDetectException; |
8 | 6 | use Detection\MobileDetect; |
9 | 7 |
|
10 | 8 | /** |
@@ -50,6 +48,13 @@ class Agent extends MobileDetect |
50 | 48 | 'WeChat' => 'MicroMessenger', |
51 | 49 | ]; |
52 | 50 |
|
| 51 | + /** |
| 52 | + * Key value store for resolved strings. |
| 53 | + * |
| 54 | + * @var array<string, mixed> |
| 55 | + */ |
| 56 | + protected $store = []; |
| 57 | + |
53 | 58 | /** |
54 | 59 | * Get the platform name from the User Agent. |
55 | 60 | * |
@@ -126,24 +131,18 @@ protected function findDetectionRulesAgainstUserAgent(array $rules) |
126 | 131 | * @param string $key |
127 | 132 | * @param \Closure():mixed $callback |
128 | 133 | * @return mixed |
129 | | - * |
130 | | - * @throws \Detection\Exception\MobileDetectException |
131 | 134 | */ |
132 | 135 | protected function retrieveUsingCacheOrResolve(string $key, Closure $callback) |
133 | 136 | { |
134 | | - try { |
135 | | - $cacheKey = $this->createCacheKey($key); |
| 137 | + $cacheKey = $this->createCacheKey($key); |
136 | 138 |
|
137 | | - if (! is_null($cacheItem = $this->cache->get($cacheKey))) { |
138 | | - return $cacheItem->get(); |
139 | | - } |
140 | | - |
141 | | - return tap(call_user_func($callback), function ($result) use ($cacheKey) { |
142 | | - $this->cache->set($cacheKey, $result); |
143 | | - }); |
144 | | - } catch (CacheException $e) { |
145 | | - throw new MobileDetectException("Cache problem in for {$key}: {$e->getMessage()}"); |
| 139 | + if (! is_null($cacheItem = $this->store[$cacheKey] ?? null)) { |
| 140 | + return $cacheItem; |
146 | 141 | } |
| 142 | + |
| 143 | + return tap(call_user_func($callback), function ($result) use ($cacheKey) { |
| 144 | + $this->store[$cacheKey] = $result; |
| 145 | + }); |
147 | 146 | } |
148 | 147 |
|
149 | 148 | /** |
|
0 commit comments