Cache always in memory?
How to choose data storage.
# use cache to optimize
class UserService:
def getUser(self, userId):
key = "userId::%s" %userId
user = cache.get(key)
if (user):
return user
user = database.get(userId)
return user
def setUser(self, user):
key = "userId::%s" %userId
# always delete user first
# make sure single source of truth
# better not modify cache.
cache.delete(key)
database.set(user)
AuthService: authentication
UserService: get user profile