From 64c7590fad839621458e706ac2d571694e959a4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mois=C3=A9s?= <7888669+moisses89@users.noreply.github.com> Date: Thu, 29 Aug 2024 17:19:10 +0200 Subject: [PATCH] Add configurable cache to all_transactions (#2198) --- safe_transaction_service/__init__.py | 2 +- .../history/services/transaction_service.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/safe_transaction_service/__init__.py b/safe_transaction_service/__init__.py index b6f050471..ad5d0de7c 100644 --- a/safe_transaction_service/__init__.py +++ b/safe_transaction_service/__init__.py @@ -1,4 +1,4 @@ -__version__ = "5.8.1" +__version__ = "5.8.2" __version_info__ = tuple( int(num) if num.isdigit() else num for num in __version__.replace("-", ".", 1).split(".") diff --git a/safe_transaction_service/history/services/transaction_service.py b/safe_transaction_service/history/services/transaction_service.py index 990562d7b..09f2830cb 100644 --- a/safe_transaction_service/history/services/transaction_service.py +++ b/safe_transaction_service/history/services/transaction_service.py @@ -4,6 +4,7 @@ from datetime import timedelta from typing import Any, Dict, List, Optional, Sequence, Tuple, Union +from django.conf import settings from django.db.models import QuerySet from django.utils import timezone @@ -57,6 +58,7 @@ class TransactionService: def __init__(self, ethereum_client: EthereumClient, redis: Redis): self.ethereum_client = ethereum_client self.redis = redis + self.cache_expiration = settings.CACHE_ALL_TXS_VIEW # Cache methods --------------------------------- def get_cache_key(self, safe_address: str, tx_id: str): @@ -100,7 +102,7 @@ def store_txs_in_cache( pipe = self.redis.pipeline() pipe.mset(to_store) for key in to_store.keys(): - pipe.expire(key, 60 * 60) # Expire in one hour + pipe.expire(key, self.cache_expiration) pipe.execute() # End of cache methods ----------------------------