Closed npelov closed 1 year ago
Is there any reason isMobile() method doesn't cache matches in matchDetectionRulesAgainstUA()?
This is a mistake on my part, I should have cached this, but probably at that point I realized that my cache key should be based on userAgent
string value. In matchUAAgainstKey
I used the name of the method which is probably not that great to begin with. I probably avoided to create a cache key based on User Agent string
+ HTTP headers array
If you call isMobile() and then isIphone it'll run match again while it could be cached. Also if you run isIPhone() the result will be cached, but then if you run isMoible() the cache won't be used.
As a side note - I'm not sure why match() method is public. it is not useful since by itself it doesn't detect anything.
Should be protected, probably I was thinking to allow people to use custom regexes.
Might be a good idea to make it protected
and then whoever extends MobileDetect
can work with it.
This is clearly a bug. setUserAgent
resets the $cache.
I will fix this and cache based on User Agent string
+ HTTP headers array
I have fixed this in https://github.com/serbanghita/Mobile-Detect/releases/tag/4.8.01 This is a major refactor, I added support for PSR-16 cache
@npelov Nikolay, thank you for the detailed write-up, it helped me get motivated to release this new version with fixes.
Is there any reason isMobile() method doesn't cache matches in matchDetectionRulesAgainstUA()?
Issue description
If you call
isMobile()
and then isIphone it'll run match again while it could be cached. Also if you runisIPhone()
the result will be cached, but then if you runisMoible()
the cache won't be used.Suggestions
As a side note - I'm not sure why match() method is public. it is not useful since by itself it doesn't detect anything.
Warning! DO NOT take this code as is - it's quickly written and probably won't work correctly. It's only meant to give you ideas.
You could implement internal match (protected), Ether make
match
that method or make a new one likerunMatchWithCache()
. This method should look something like this:Then use this function inside matchUAAgainstKey like this: