zoukankan      html  css  js  c++  java
  • django缓存优化(二)

    一、缓存目的:

      1、减小过载

      2、避免重复计算

      3、提高系统性能

    二、如何进行缓存

      

    三、缓存类型

      

    四、缓存粒度分类

      

    五、缓存的设置与使用

      示例一:

    CACHES = {    
      'default': {
          'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
       'LOCATION': '127.0.0.1:11211',
      }
    }

      示例二:

    CACHES = {    
        'default': {        
            'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',  
    'LOCATION': 'unix:/tmp/memcached.sock', } }

      示例三:

    CACHES = {    
      'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': [
          '172.19.26.240:11211',
          '172.19.26.242:11211',
        ]
      }
    }

      示例四:

    CACHES = {    
      'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': [
          '172.19.26.240:11211',
          '172.19.26.242:11212',
          '172.19.26.244:11213',
        ]
      }
    }

      访问缓存:

    >>>from django.core.cache import caches
    >>>cache1 = caches[‘myalias’]
    >>>cache2 = caches[‘myalias’]
    >>>cache1 is cache2
    True
    
    
    
    >>>from django.core.cache import cache
    >>>cache.set(‘my_key’, ‘hello, world’, 30)
    >>>cache.get(‘my_key’)
    ‘hello, world!’
    >>>cache.get(‘my_key’)
    None
    >>>cache.get(‘my_key’,‘has expired’)
    ‘has expired’

    六、缓存原理

    明月装饰了你的窗子,你装饰了他的梦。
  • 相关阅读:
    方法是Objective-C独有的一种结构,只能在Objective-C中声明、定义和使用,C语言不能声明、定义和使用
    NSDate
    runtime
    iOS开发常用的工具
    程序的国际化
    经常使用的iOS SDK库和第三方库
    RunLoop是什么?
    狼若回头,必有理由
    第1年1月21日 Guard Malloc
    第1年1月10日 flv格式
  • 原文地址:https://www.cnblogs.com/zkkysqs/p/9539629.html
Copyright © 2011-2022 走看看