[refactor]: improve code about strategy cache
parent
a07e261677
commit
1fc3a36ab2
12
README.md
12
README.md
|
@ -1218,11 +1218,13 @@ The application is responsible for reading and writing from storage. The cache
|
||||||
```python
|
```python
|
||||||
def get_user(self, user_id):
|
def get_user(self, user_id):
|
||||||
user = cache.get("user.{0}", user_id)
|
user = cache.get("user.{0}", user_id)
|
||||||
if user is None:
|
if user:
|
||||||
user = db.query("SELECT * FROM users WHERE user_id = {0}", user_id)
|
return user
|
||||||
if user is not None:
|
|
||||||
key = "user.{0}".format(user_id)
|
user = db.query("SELECT * FROM users WHERE user_id = {0}", user_id)
|
||||||
cache.set(key, json.dumps(user))
|
if user:
|
||||||
|
key = "user.{0}".format(user_id)
|
||||||
|
cache.set(key, json.dumps(user))
|
||||||
return user
|
return user
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue