Merge pull request #1399 from mhils/fix-cv-cache-invalidation

Fix content view cache invalidation
This commit is contained in:
Maximilian Hils 2016-07-21 20:10:06 -07:00 committed by GitHub
commit 9f0889d541
5 changed files with 26 additions and 18 deletions

View File

@ -189,15 +189,21 @@ class FlowView(tabs.Tabs):
limit = sys.maxsize limit = sys.maxsize
else: else:
limit = contentviews.VIEW_CUTOFF limit = contentviews.VIEW_CUTOFF
flow_modify_cache_invalidation = hash((
message.raw_content,
message.headers.fields,
getattr(message, "path", None),
))
return cache.get( return cache.get(
self._get_content_view, # We move message into this partial function as it is not hashable.
lambda *args: self._get_content_view(message, *args),
viewmode, viewmode,
message,
limit, limit,
message # Cache invalidation flow_modify_cache_invalidation
) )
def _get_content_view(self, viewmode, message, max_lines, _): def _get_content_view(self, message, viewmode, max_lines, _):
try: try:
content = message.content content = message.content

View File

@ -32,9 +32,6 @@ class MessageData(basetypes.Serializable):
def __ne__(self, other): def __ne__(self, other):
return not self.__eq__(other) return not self.__eq__(other)
def __hash__(self):
return hash(frozenset(self.__dict__.items()))
def set_state(self, state): def set_state(self, state):
for k, v in state.items(): for k, v in state.items():
if k == "headers": if k == "headers":
@ -77,9 +74,6 @@ class Message(basetypes.Serializable):
def __ne__(self, other): def __ne__(self, other):
return not self.__eq__(other) return not self.__eq__(other)
def __hash__(self):
return hash(self.data) ^ 1
def get_state(self): def get_state(self):
return self.data.get_state() return self.data.get_state()

View File

@ -79,9 +79,6 @@ class _MultiDict(MutableMapping, basetypes.Serializable):
def __ne__(self, other): def __ne__(self, other):
return not self.__eq__(other) return not self.__eq__(other)
def __hash__(self):
return hash(self.fields)
def get_all(self, key): def get_all(self, key):
""" """
Return the list of all values for a given key. Return the list of all values for a given key.
@ -241,6 +238,9 @@ class ImmutableMultiDict(MultiDict):
__delitem__ = set_all = insert = _immutable __delitem__ = set_all = insert = _immutable
def __hash__(self):
return hash(self.fields)
def with_delitem(self, key): def with_delitem(self, key):
""" """
Returns: Returns:

View File

@ -71,10 +71,6 @@ class TestMessage(object):
assert resp != 0 assert resp != 0
def test_hash(self):
resp = tresp()
assert hash(resp)
def test_serializable(self): def test_serializable(self):
resp = tresp() resp = tresp()
resp2 = http.Response.from_state(resp.get_state()) resp2 = http.Response.from_state(resp.get_state())

View File

@ -45,7 +45,7 @@ class TestMultiDict(object):
assert md["foo"] == "bar" assert md["foo"] == "bar"
with tutils.raises(KeyError): with tutils.raises(KeyError):
md["bar"] assert md["bar"]
md_multi = TMultiDict( md_multi = TMultiDict(
[("foo", "a"), ("foo", "b")] [("foo", "a"), ("foo", "b")]
@ -101,6 +101,15 @@ class TestMultiDict(object):
assert TMultiDict() != self._multi() assert TMultiDict() != self._multi()
assert TMultiDict() != 42 assert TMultiDict() != 42
def test_hash(self):
"""
If a class defines mutable objects and implements an __eq__() method,
it should not implement __hash__(), since the implementation of hashable
collections requires that a key's hash value is immutable.
"""
with tutils.raises(TypeError):
assert hash(TMultiDict())
def test_get_all(self): def test_get_all(self):
md = self._multi() md = self._multi()
assert md.get_all("foo") == ["bar"] assert md.get_all("foo") == ["bar"]
@ -197,6 +206,9 @@ class TestImmutableMultiDict(object):
with tutils.raises(TypeError): with tutils.raises(TypeError):
md.add("foo", "bar") md.add("foo", "bar")
def test_hash(self):
assert hash(TImmutableMultiDict())
def test_with_delitem(self): def test_with_delitem(self):
md = TImmutableMultiDict([("foo", "bar")]) md = TImmutableMultiDict([("foo", "bar")])
assert md.with_delitem("foo").fields == () assert md.with_delitem("foo").fields == ()