File tree Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change 1
- PWD = $(shell pwd)
2
-
3
- all : prep test
1
+ all : prep test
4
2
5
3
prep :
6
4
# git submodule update --init
7
5
# sudo apt-get install python-yaml
8
-
6
+
9
7
test :
10
8
@# test ! -d tmp && mkdir tmp
11
9
@export PYTHONPATH=tmp && python setup.py develop -d tmp
23
21
dist\
24
22
build
25
23
26
- .PHONY : all clean
24
+ .PHONY : all prep test clean
Original file line number Diff line number Diff line change @@ -196,6 +196,10 @@ def Parse(self, user_agent_string):
196
196
return device , brand , model
197
197
198
198
199
+ MAX_CACHE_SIZE = 20
200
+ _parse_cache = {}
201
+
202
+
199
203
def Parse (user_agent_string , ** jsParseBits ):
200
204
""" Parse all the things
201
205
Args:
@@ -205,12 +209,20 @@ def Parse(user_agent_string, **jsParseBits):
205
209
A dictionary containing all parsed bits
206
210
"""
207
211
jsParseBits = jsParseBits or {}
208
- return {
212
+ key = (user_agent_string , repr (jsParseBits ))
213
+ cached = _parse_cache .get (key )
214
+ if cached is not None :
215
+ return cached
216
+ if len (_parse_cache ) > MAX_CACHE_SIZE :
217
+ _parse_cache .clear ()
218
+ v = {
209
219
'user_agent' : ParseUserAgent (user_agent_string , ** jsParseBits ),
210
220
'os' : ParseOS (user_agent_string , ** jsParseBits ),
211
221
'device' : ParseDevice (user_agent_string , ** jsParseBits ),
212
222
'string' : user_agent_string
213
223
}
224
+ _parse_cache [key ] = v
225
+ return v
214
226
215
227
216
228
def ParseUserAgent (user_agent_string , ** jsParseBits ):
You can’t perform that action at this time.
0 commit comments