From 1fc3a36ab2abaf60b0e440229817a00097f09b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abra=C3=A3o=20=C3=81llysson=20dos=20Santos=20Hon=C3=B3rio?= Date: Wed, 10 May 2023 18:16:18 -0300 Subject: [PATCH] [refactor]: improve code about strategy cache --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7f41e7bd..54d568ab 100644 --- a/README.md +++ b/README.md @@ -1218,11 +1218,13 @@ The application is responsible for reading and writing from storage. The cache ```python def get_user(self, user_id): user = cache.get("user.{0}", user_id) - if user is None: - user = db.query("SELECT * FROM users WHERE user_id = {0}", user_id) - if user is not None: - key = "user.{0}".format(user_id) - cache.set(key, json.dumps(user)) + if user: + return user + + user = db.query("SELECT * FROM users WHERE user_id = {0}", user_id) + if user: + key = "user.{0}".format(user_id) + cache.set(key, json.dumps(user)) return user ```