缓存数据
缓存数据的类型
在设计缓存的数据时,可以缓存以下类型的数据
-
一个数值
例如
- 验证码
-
用户状态
如:user:{user_id}: enable
-
数据库记录,
-
Caching at the object level
以数据库对象的角度考虑, 应用更普遍
例如, 用户的基本信息
user = User.query.filter_by(id=1).first() user -> User对象 { 'user_id':1, 'user_name': 'python', 'age': 28, 'introduction': '' }
-
Caching at the database query level
以数据库查询的角度考虑,应用场景较特殊,一般仅针对较复杂的查询进行使用
query_result = User.query.join(User.profile).filter_by(id=1).first() -> sql = "select a.user_id, a.user_name, b.gender, b.birthday from tbl_user as a inner join tbl_profile as b on a.user_id=b.user_id where a.
-