Skip to content

Commit b2c664b

Browse files
committed
Refactor
1 parent 3ead8b9 commit b2c664b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

django_mongodb_backend/cache.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,17 @@ class CacheEntry:
5757

5858

5959
class MongoDBCache(BaseDatabaseCache):
60+
# This class uses collection provided by the database connection.
61+
62+
pickle_protocol = pickle.HIGHEST_PROTOCOL
63+
6064
def create_indexes(self):
6165
self.collection.create_index("expires_at", expireAfterSeconds=0)
6266
self.collection.create_index("key", unique=True)
6367

6468
@cached_property
6569
def serializer(self):
66-
return MongoSerializer()
70+
return MongoSerializer(self.pickle_protocol)
6771

6872
@property
6973
def _db(self):
@@ -176,9 +180,9 @@ def touch(self, key, timeout=DEFAULT_TIMEOUT, version=None):
176180
return res.matched_count > 0
177181

178182
def _get_expiration_time(self, timeout=None):
179-
timestamp = self.get_backend_timeout(timeout)
180183
if timeout is None:
181184
return None
185+
timestamp = self.get_backend_timeout(timeout)
182186
return datetime.fromtimestamp(timestamp, tz=timezone.utc)
183187

184188
def delete(self, key, version=None):

0 commit comments

Comments
 (0)