ua-parser / uap-python

Python implementation of ua-parser
Apache License 2.0
561 stars 152 forks source link

In S3 and SIEVE, don't evict when updating an entry #201

Closed masklinn closed 6 months ago

masklinn commented 7 months ago

The caching protocol is such that to update a partial result with more domains it has to be re-set.

While the LRU implementation evicts after insertion, the S3 and SIEVE insertions first make room for an entry, then insert the new entry.

For partial entry this is unnecessary, and can create odd states where there are multiple entries in the fifo with different data but the same key. Instead, since the cache entries are mutable (unlike the results) the value should simply be updated in place. The hit has already been recorded since the __getitem__ which retrieved the partial entry.

Beware: in S3, do not confuse a cache hit with a ghost cache hit, the second should not suppress the insertion.