summaryrefslogtreecommitdiff
path: root/kombu/message.py
diff options
context:
space:
mode:
authorAsk Solem <ask@celeryproject.org>2015-12-08 12:07:38 -0800
committerAsk Solem <ask@celeryproject.org>2015-12-08 12:07:38 -0800
commit7ece04ed25b69b6517753fc5541916b50e52e65b (patch)
treea42f46ad36e4f4ce0248fa8c541fc6a0c35f1892 /kombu/message.py
parent71db3a8cd976df57586801ed46cb026b27bb7f30 (diff)
downloadkombu-7ece04ed25b69b6517753fc5541916b50e52e65b.tar.gz
Message.decode() is now cached.
Diffstat (limited to 'kombu/message.py')
-rw-r--r--kombu/message.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/kombu/message.py b/kombu/message.py
index d9274d5a..c1f2f98d 100644
--- a/kombu/message.py
+++ b/kombu/message.py
@@ -137,7 +137,17 @@ class Message(object):
def decode(self):
"""Deserialize the message body, returning the original
- python structure sent by the publisher."""
+ python structure sent by the publisher.
+
+ Note: The return value is memoized, use `_decode` to force
+ re-evaluation.
+
+ """
+ if not self._decoded_cache:
+ self._decoded_cache = self._decode()
+ return self._decoded_cache
+
+ def _decode(self):
return loads(self.body, self.content_type,
self.content_encoding, accept=self.accept)
@@ -149,9 +159,7 @@ class Message(object):
@property
def payload(self):
"""The decoded message body."""
- if not self._decoded_cache:
- self._decoded_cache = self.decode()
- return self._decoded_cache
+ return self._decoded_cache if self._decoded_cache else self.decode()
def __repr__(self):
details = {