Skip to content

Commit bf73e5c

Browse files
authored
Merge branch 'master' into release
2 parents 0b7b683 + f5ba8db commit bf73e5c

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

doc/guides.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,9 @@ composing :class:`~ua_parser.Resolver` objects.
9393
The most basic such customisation is simply configuring caching away
9494
from the default setup.
9595

96-
As an example, in the default configuration if |regex|_ is available
97-
the regex-based resolver is not cached, a user might consider the
98-
memory investment worth it and want to reconfigure the stack for a
99-
cached base.
96+
As an example, all resolvers are cached with an
97+
:class:`~ua_parser.caching.S3Fifo` of size 2000, a user's workload
98+
might lead them to favor a larger LRU.
10099

101100
The process is uncomplicated as the APIs are designed to compose
102101
together.
@@ -112,7 +111,7 @@ the relevant :class:`Matchers` data::
112111
The next step is to instantiate the cache [#cache]_ suitably
113112
configured::
114113

115-
cache = ua_parser.Cache(1000)
114+
cache = ua_parser.caching.Lru(10000)
116115

117116
And compose the base resolver and cache together::
118117

@@ -136,6 +135,11 @@ from here on::
136135
:class:`~ua_parser.caching.Local`, which is also caching-related,
137136
and serves to use thread-local caches rather than a shared cache.
138137

138+
Although this does not remove the cache locks it avoids contention
139+
on the locks, which can be useful when using a free-threaded
140+
interpreter, especially when using the LRU cache as it has to
141+
synchronise on hit.
142+
139143
.. _builtin-resolvers:
140144

141145
Builtin Resolvers

src/ua_parser/__init__.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,7 @@
6868
if importlib.util.find_spec("ua_parser_rs"):
6969
from .regex import Resolver as RegexResolver
7070
BestAvailableResolver: _ResolverCtor = next(
71-
filter(
72-
None,
73-
(
74-
RegexResolver,
75-
Re2Resolver,
76-
lambda m: CachingResolver(BasicResolver(m), Cache(2000)),
77-
),
78-
)
71+
filter(None, (RegexResolver, Re2Resolver, BasicResolver))
7972
)
8073

8174

@@ -97,7 +90,7 @@ def from_matchers(cls, m: Matchers, /) -> Parser:
9790
stack.
9891
9992
"""
100-
return cls(BestAvailableResolver(m))
93+
return cls(CachingResolver(BestAvailableResolver(m), Cache(2000)))
10194

10295
def __init__(self, resolver: Resolver) -> None:
10396
self.resolver = resolver

0 commit comments

Comments
 (0)