Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
146ed13a
Kaydet (Commit)
146ed13a
authored
Eki 30, 2012
tarafından
Aymeric Augustin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #17083 -- Allowed sessions to use non-default cache.
üst
68847135
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
48 additions
and
6 deletions
+48
-6
global_settings.py
django/conf/global_settings.py
+1
-0
cache.py
django/contrib/sessions/backends/cache.py
+3
-2
tests.py
django/contrib/sessions/tests.py
+22
-4
settings.txt
docs/ref/settings.txt
+10
-0
1.5.txt
docs/releases/1.5.txt
+3
-0
sessions.txt
docs/topics/http/sessions.txt
+9
-0
No files found.
django/conf/global_settings.py
Dosyayı görüntüle @
146ed13a
...
...
@@ -445,6 +445,7 @@ MIDDLEWARE_CLASSES = (
# SESSIONS #
############
SESSION_CACHE_ALIAS
=
'default'
# Cache to store session data if using the cache session backend.
SESSION_COOKIE_NAME
=
'sessionid'
# Cookie name. This can be whatever you want.
SESSION_COOKIE_AGE
=
60
*
60
*
24
*
7
*
2
# Age of cookie, in seconds (default: 2 weeks).
SESSION_COOKIE_DOMAIN
=
None
# A string like ".example.com", or None for standard domain cookie.
...
...
django/contrib/sessions/backends/cache.py
Dosyayı görüntüle @
146ed13a
from
django.conf
import
settings
from
django.contrib.sessions.backends.base
import
SessionBase
,
CreateError
from
django.core.cache
import
cache
from
django.core.cache
import
get_
cache
from
django.utils.six.moves
import
xrange
KEY_PREFIX
=
"django.contrib.sessions.cache"
...
...
@@ -10,7 +11,7 @@ class SessionStore(SessionBase):
A cache-based session store.
"""
def
__init__
(
self
,
session_key
=
None
):
self
.
_cache
=
cache
self
.
_cache
=
get_cache
(
settings
.
SESSION_CACHE_ALIAS
)
super
(
SessionStore
,
self
)
.
__init__
(
session_key
)
@property
...
...
django/contrib/sessions/tests.py
Dosyayı görüntüle @
146ed13a
...
...
@@ -13,8 +13,8 @@ from django.contrib.sessions.backends.file import SessionStore as FileSession
from
django.contrib.sessions.backends.signed_cookies
import
SessionStore
as
CookieSession
from
django.contrib.sessions.models
import
Session
from
django.contrib.sessions.middleware
import
SessionMiddleware
from
django.core.cache
import
get_cache
from
django.core
import
management
from
django.core.cache
import
DEFAULT_CACHE_ALIAS
from
django.core.exceptions
import
ImproperlyConfigured
,
SuspiciousOperation
from
django.http
import
HttpResponse
from
django.test
import
TestCase
,
RequestFactory
...
...
@@ -136,8 +136,8 @@ class SessionTestsMixin(object):
self
.
assertTrue
(
self
.
session
.
modified
)
def
test_save
(
self
):
if
(
hasattr
(
self
.
session
,
'_cache'
)
and
'DummyCache'
in
settings
.
CACHES
[
DEFAULT
_CACHE_ALIAS
][
'BACKEND'
]):
if
(
hasattr
(
self
.
session
,
'_cache'
)
and
'DummyCache'
in
settings
.
CACHES
[
settings
.
SESSION
_CACHE_ALIAS
][
'BACKEND'
]):
raise
unittest
.
SkipTest
(
"Session saving tests require a real cache backend"
)
self
.
session
.
save
()
self
.
assertTrue
(
self
.
session
.
exists
(
self
.
session
.
session_key
))
...
...
@@ -355,7 +355,8 @@ class CacheDBSessionTests(SessionTestsMixin, TestCase):
backend
=
CacheDBSession
@unittest.skipIf
(
'DummyCache'
in
settings
.
CACHES
[
DEFAULT_CACHE_ALIAS
][
'BACKEND'
],
@unittest.skipIf
(
'DummyCache'
in
settings
.
CACHES
[
settings
.
SESSION_CACHE_ALIAS
][
'BACKEND'
],
"Session saving tests require a real cache backend"
)
def
test_exists_searches_cache_first
(
self
):
self
.
session
.
save
()
...
...
@@ -454,6 +455,23 @@ class CacheSessionTests(SessionTestsMixin, unittest.TestCase):
self
.
session
.
_session_key
=
(
string
.
ascii_letters
+
string
.
digits
)
*
20
self
.
assertEqual
(
self
.
session
.
load
(),
{})
def
test_default_cache
(
self
):
self
.
session
.
save
()
self
.
assertNotEqual
(
get_cache
(
'default'
)
.
get
(
self
.
session
.
cache_key
),
None
)
@override_settings
(
CACHES
=
{
'default'
:
{
'BACKEND'
:
'django.core.cache.backends.dummy.DummyCache'
,
},
'sessions'
:
{
'BACKEND'
:
'django.core.cache.backends.locmem.LocMemCache'
,
},
},
SESSION_CACHE_ALIAS
=
'sessions'
)
def
test_non_default_cache
(
self
):
self
.
session
.
save
()
self
.
assertEqual
(
get_cache
(
'default'
)
.
get
(
self
.
session
.
cache_key
),
None
)
self
.
assertNotEqual
(
get_cache
(
'sessions'
)
.
get
(
self
.
session
.
cache_key
),
None
)
class
SessionMiddlewareTests
(
unittest
.
TestCase
):
...
...
docs/ref/settings.txt
Dosyayı görüntüle @
146ed13a
...
...
@@ -1693,6 +1693,16 @@ This is useful if you have multiple Django instances running under the same
hostname. They can use different cookie paths, and each instance will only see
its own session cookie.
.. setting:: SESSION_CACHE_ALIAS
SESSION_CACHE_ALIAS
-------------------
Default: ``default``
If you're using :ref:`cache-based session storage <cached-sessions-backend>`,
this selects the cache to use.
.. setting:: SESSION_COOKIE_SECURE
SESSION_COOKIE_SECURE
...
...
docs/releases/1.5.txt
Dosyayı görüntüle @
146ed13a
...
...
@@ -299,6 +299,9 @@ Django 1.5 also includes several smaller improvements worth noting:
* RemoteUserMiddleware now forces logout when the REMOTE_USER header
disappears during the same browser session.
* The :ref:`cache-based session backend <cached-sessions-backend>` can store
session data in a non-default cache.
Backwards incompatible changes in 1.5
=====================================
...
...
docs/topics/http/sessions.txt
Dosyayı görüntüle @
146ed13a
...
...
@@ -45,6 +45,8 @@ If you want to use a database-backed session, you need to add
Once you have configured your installation, run ``manage.py syncdb``
to install the single database table that stores session data.
.. _cached-sessions-backend:
Using cached sessions
---------------------
...
...
@@ -62,6 +64,13 @@ sure you've configured your cache; see the :doc:`cache documentation
sessions directly instead of sending everything through the file or
database cache backends.
If you have multiple caches defined in :setting:`CACHES`, Django will use the
default cache. To use another cache, set :setting:`SESSION_CACHE_ALIAS` to the
name of that cache.
.. versionchanged:: 1.5
The :setting:`SESSION_CACHE_ALIAS` setting was added.
Once your cache is configured, you've got two choices for how to store data in
the cache:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment