osglworks / java-tool

Some simple common Java utilities
Apache License 2.0
52 stars 18 forks source link

`UserAgent` - use LFU cache to replace hash map #234

Closed greenlaw110 closed 4 years ago

greenlaw110 commented 4 years ago

UserAgent parsing is at the moment use HashMap to cache processed user agent string. The problem of this approach is the HashMap could be very big in a real web site: according to https://developers.whatismybrowser.com/useragents/explore/ there could be over 24M user agent strings, this could easily eat up heap of your VM.

This CR is to use a LFU cache to replace hash map, thus the number of cached user agent could be caped, e.g. 1000.