Ticket #6791: cached_db_docs_and_tests.diff
File cached_db_docs_and_tests.diff, 5.5 KB (added by , 17 years ago) |
---|
-
django/conf/global_settings.py
279 279 # SESSIONS # 280 280 ############ 281 281 282 SESSION_COOKIE_NAME = 'sessionid' # Cookie name. This can be whatever you want.283 SESSION_COOKIE_AGE = 60 * 60 * 24 * 7 * 2 # Age of cookie, in seconds (default: 2 weeks).284 SESSION_COOKIE_DOMAIN = None # A string like ".lawrence.com", or None for standard domain cookie.285 SESSION_COOKIE_SECURE = False # Whether the session cookie should be secure (https:// only).286 SESSION_COOKIE_PATH = '/' # The path of the session cookie.287 SESSION_SAVE_EVERY_REQUEST = False # Whether to save the session data on every request.288 SESSION_EXPIRE_AT_BROWSER_CLOSE = False # Whether sessions expire when a user closes his browser.289 SESSION_ENGINE = 'django.contrib.sessions.backends. db' # The module to store session data290 SESSION_FILE_PATH = '/tmp/' # Directory to store session files if using the file session module282 SESSION_COOKIE_NAME = 'sessionid' # Cookie name. This can be whatever you want. 283 SESSION_COOKIE_AGE = 60 * 60 * 24 * 7 * 2 # Age of cookie, in seconds (default: 2 weeks). 284 SESSION_COOKIE_DOMAIN = None # A string like ".lawrence.com", or None for standard domain cookie. 285 SESSION_COOKIE_SECURE = False # Whether the session cookie should be secure (https:// only). 286 SESSION_COOKIE_PATH = '/' # The path of the session cookie. 287 SESSION_SAVE_EVERY_REQUEST = False # Whether to save the session data on every request. 288 SESSION_EXPIRE_AT_BROWSER_CLOSE = False # Whether sessions expire when a user closes his browser. 289 SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db' # The module to store session data 290 SESSION_FILE_PATH = '/tmp/' # Directory to store session files if using the file session module 291 291 292 292 ######### 293 293 # CACHE # -
django/contrib/sessions/tests.py
3 3 >>> from django.conf import settings 4 4 >>> from django.contrib.sessions.backends.db import SessionStore as DatabaseSession 5 5 >>> from django.contrib.sessions.backends.cache import SessionStore as CacheSession 6 >>> from django.contrib.sessions.backends.cached_db import SessionStore as CacheDBSession 6 7 >>> from django.contrib.sessions.backends.file import SessionStore as FileSession 7 8 >>> from django.contrib.sessions.backends.base import SessionBase 8 9 … … 23 24 >>> db_session.exists(db_session.session_key) 24 25 False 25 26 27 >>> cdb_session = CacheDBSession() 28 >>> cdb_session.modified 29 False 30 >>> cdb_session['cat'] = "dog" 31 >>> cdb_session.modified 32 True 33 >>> cdb_session.pop('cat') 34 'dog' 35 >>> cdb_session.pop('some key', 'does not exist') 36 'does not exist' 37 >>> cdb_session.save() 38 >>> cdb_session.exists(cdb_session.session_key) 39 True 40 >>> cdb_session.delete(cdb_session.session_key) 41 >>> cdb_session.exists(cdb_session.session_key) 42 False 43 26 44 >>> file_session = FileSession() 27 45 >>> file_session.modified 28 46 False -
docs/sessions.txt
53 53 sure to check that your Web server has permissions to read and write to 54 54 this location. 55 55 56 Using cache -based sessions57 --------------------- -----56 Using cached sessions 57 --------------------- 58 58 59 To store session data using Django's cache system, set ``SESSION_ENGINE`` 60 to ``"django.contrib.sessions.backends.cache"``. You'll want to make sure 61 you've configured your cache; see the `cache documentation`_ for details. 59 There are two cache backends for Django. Setting ``SESSION_ENGINE`` to 60 ``"django.contrib.sessions.backends.cache"`` uses a simple caching session 61 store, while ``"django.contrib.sessions.backends.cached_db"`` uses a 62 write-through cache. In a write-through cache, every write to the cache 63 causes a write to the backing store, while reads only use the backing store 64 on a cache miss. Both session stores offer high performance, but the simple 65 cache store trades more performance for persistence. 62 66 67 You'll want to make sure you've configured your cache; see the 68 `cache documentation`_ for details. 69 63 70 .. _cache documentation: ../cache/ 64 71 65 72 .. note:: 73 If you decide to use the ``cache`` session store, you should 74 probably only use the memcached cache backend. The local memory and simple 75 cache backends don't retain data long enough to be good choices; It'll be 76 faster to use file or database sessions directly instead of sending 77 everything through the file or database cache backends. 66 78 67 You should probably only use cache-based sessions if you're using the68 memcached cache backend. The local memory and simple cache backends69 don't retain data long enough to be good choices, and it'll be faster70 to use file or database sessions directly instead of sending everything71 through the file or database cache backends.72 79 80 73 81 Using sessions in views 74 82 ======================= 75 83