aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mitmproxy/tools/console/common.py7
-rw-r--r--mitmproxy/tools/console/flowview.py14
-rw-r--r--test/mitmproxy/test_utils_lrucache.py34
3 files changed, 6 insertions, 49 deletions
diff --git a/mitmproxy/tools/console/common.py b/mitmproxy/tools/console/common.py
index 90dce5ae..78860702 100644
--- a/mitmproxy/tools/console/common.py
+++ b/mitmproxy/tools/console/common.py
@@ -7,7 +7,7 @@ import urwid
import urwid.util
import mitmproxy.net
-from mitmproxy.utils import lrucache
+from functools import lru_cache
from mitmproxy.tools.console import signals
from mitmproxy import export
from mitmproxy.utils import human
@@ -325,9 +325,8 @@ def export_to_clip_or_file(key, scope, flow, writer):
else: # other keys
writer(exporter(flow))
-flowcache = lrucache.LRUCache(800)
-
+@lru_cache(maxsize=800)
def raw_format_flow(f):
f = dict(f)
pile = []
@@ -458,4 +457,4 @@ def format_flow(f, focus, extended=False, hostheader=False, max_url_len=False):
else:
d["resp_ctype"] = ""
- return flowcache.get(raw_format_flow, tuple(sorted(d.items())))
+ return raw_format_flow(tuple(sorted(d.items())))
diff --git a/mitmproxy/tools/console/flowview.py b/mitmproxy/tools/console/flowview.py
index 5ac61bb7..50da1835 100644
--- a/mitmproxy/tools/console/flowview.py
+++ b/mitmproxy/tools/console/flowview.py
@@ -8,7 +8,6 @@ from typing import Optional, Union # noqa
from mitmproxy import contentviews
from mitmproxy import http
-from mitmproxy.utils import lrucache
from mitmproxy.tools.console import common
from mitmproxy.tools.console import flowdetailview
from mitmproxy.tools.console import grideditor
@@ -18,6 +17,7 @@ from mitmproxy.tools.console import tabs
from mitmproxy import export
from mitmproxy.net.http import Headers
from mitmproxy.net.http import status_codes
+from functools import lru_cache
class SearchError(Exception):
@@ -120,9 +120,6 @@ class FlowViewHeader(urwid.WidgetWrap):
hostheader=self.master.options.showhost
)
-
-cache = lrucache.LRUCache(200)
-
TAB_REQ = 0
TAB_RESP = 1
@@ -193,14 +190,9 @@ class FlowView(tabs.Tabs):
message.headers.fields,
getattr(message, "path", None),
))
- return cache.get(
- # We move message into this partial function as it is not hashable.
- lambda *args: self._get_content_view(message, *args),
- viewmode,
- limit,
- flow_modify_cache_invalidation
- )
+ return lambda *args: self._get_content_view(message, viewmode, limit, flow_modify_cache_invalidation)
+ @lru_cache(maxsize=200)
def _get_content_view(self, message, viewmode, max_lines, _):
description, lines, error = contentviews.get_message_content_view(
viewmode, message
diff --git a/test/mitmproxy/test_utils_lrucache.py b/test/mitmproxy/test_utils_lrucache.py
deleted file mode 100644
index 07b96b4d..00000000
--- a/test/mitmproxy/test_utils_lrucache.py
+++ /dev/null
@@ -1,34 +0,0 @@
-from mitmproxy.utils import lrucache
-
-
-def test_LRUCache():
- cache = lrucache.LRUCache(2)
-
- class Foo:
- ran = False
-
- def gen(self, x):
- self.ran = True
- return x
- f = Foo()
-
- assert not f.ran
- assert cache.get(f.gen, 1) == 1
- assert f.ran
- f.ran = False
- assert cache.get(f.gen, 1) == 1
- assert not f.ran
-
- f.ran = False
- assert cache.get(f.gen, 1) == 1
- assert not f.ran
- assert cache.get(f.gen, 2) == 2
- assert cache.get(f.gen, 3) == 3
- assert f.ran
-
- f.ran = False
- assert cache.get(f.gen, 1) == 1
- assert f.ran
-
- assert len(cache.cacheList) == 2
- assert len(cache.cache) == 2