4.django缓存优化课件-iczt441解析_第1页
4.django缓存优化课件-iczt441解析_第2页
4.django缓存优化课件-iczt441解析_第3页
4.django缓存优化课件-iczt441解析_第4页
4.django缓存优化课件-iczt441解析_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Lesson4: Database缓存解析讲师:Cynthia课程内容Database缓存配置源码解析配置与使用演示Database缓存配置BACKEND:django.core.cache.backends.db.DatabaseCacheLOCATION: 数据库表名CACHES = default: BACKEND: django.core.cache.backends.db.DatabaseCache, LOCATION: my_cache_table, Database缓存配置创建缓存表使用数据库缓存之前,需要创建缓存表:python manage.py createcachetab

2、le创建的表名为缓存配置中的LOCATION值思考:Cache表创建到哪里去了呢?Database缓存配置创建缓存表配置好数据库缓存之前还需要配置数据库:DATABASES = default: NAME: app_data, ENGINE: django.db.backends.postgresql_psycopg2, USER: postgres_user, PASSWORD: password 只会创建不存在的表,如果表已经存在,不操作Database缓存配置创建缓存表疑问?可否将cache分类存储到不同的表?可否将cache分别存储到不同数据库?YESDatabase缓存配置创建缓存表

3、Mutiple Database Caches: createcachetable会为每个 Cache 创建一张缓存表Mutiple Databases: createcachetable会去查找数据库routers中的allow_migrate()方法,检查是否允许migrate。默认使用default数据库,要使用其它数据库,需要用-database参数。Multi Database CachesCACHES = default: BACKEND: django.core.cache.backends.db.DatabaseCache, LOCATION: api_cache_table,

4、 ,# 必须配置default apps: BACKEND: django.core.cache.backends.db.DatabaseCache, LOCATION: apps_cache_table, Multiple Databasesclass CacheRouter(object): A router to control all database cache operations def db_for_read(self, model, *hints): All cache read operations go to the replica def db_for_write(se

5、lf, model, *hints): All cache write operations go to primary def allow_migrate(self, db, app_label, model_name=None, *hints): Only install the cache model on primary Multiple Databases读 def db_for_read(self, model, *hints): All cache read operations go to the replica if model._meta.app_label = djang

6、o_cache: return cache_replica return None所有DB缓存的读操作指向 cache_replica DBMultiple Databases写def db_for_write(self, model, *hints): All cache write operations go to primary if model._meta.app_label = django_cache: return cache_primary return None def db_for_write(self, model, *hints): All cache write op

7、erations go to primary if model._meta.app_label = django_cache: return cache_primary return None所有DB缓存的写操作指向 cache_primary DBMultiple Databasesmigrationdef allow_migrate(self, db, app_label, model_name=None, *hints): Only install the cache model on primary if app_label = django_cache: return db = cache_primary return None允许在 cache_primary DB 上执行 migration源码解析Cache接口:getset (会调用_cull)addhas_keydeleteclear演示环境说明操作系统Ubuntu数据库MySQLDjango 版本 1.8IDE PyCharm, VIMDatabase配置与使用演示DB Cache 配置与使用Multiple DB Caches 配置与使用基于 Multiple DBs 缓存配置与使用DB router 配置与使用参考资料Djangos cache framwork Multiple dat

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论