This commit is contained in:
Abraão Állysson dos Santos Honório 2023-05-10 18:18:58 -03:00 committed by GitHub
commit 21b37a8247
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 5 deletions

View File

@ -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
```