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
0104b5a4
Kaydet (Commit)
0104b5a4
authored
Şub 15, 2019
tarafından
Jakub Szafrański
Kaydeden (comit)
Tim Graham
Şub 15, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #30181 -- Made cache.get() with default work correctly on PyLibMCCache if None is cached.
üst
741ce81a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
4 deletions
+24
-4
memcached.py
django/core/cache/backends/memcached.py
+11
-4
tests.py
tests/cache/tests.py
+13
-0
No files found.
django/core/cache/backends/memcached.py
Dosyayı görüntüle @
0104b5a4
...
@@ -68,10 +68,7 @@ class BaseMemcachedCache(BaseCache):
...
@@ -68,10 +68,7 @@ class BaseMemcachedCache(BaseCache):
def
get
(
self
,
key
,
default
=
None
,
version
=
None
):
def
get
(
self
,
key
,
default
=
None
,
version
=
None
):
key
=
self
.
make_key
(
key
,
version
=
version
)
key
=
self
.
make_key
(
key
,
version
=
version
)
val
=
self
.
_cache
.
get
(
key
)
return
self
.
_cache
.
get
(
key
,
default
)
if
val
is
None
:
return
default
return
val
def
set
(
self
,
key
,
value
,
timeout
=
DEFAULT_TIMEOUT
,
version
=
None
):
def
set
(
self
,
key
,
value
,
timeout
=
DEFAULT_TIMEOUT
,
version
=
None
):
key
=
self
.
make_key
(
key
,
version
=
version
)
key
=
self
.
make_key
(
key
,
version
=
version
)
...
@@ -163,6 +160,16 @@ class MemcachedCache(BaseMemcachedCache):
...
@@ -163,6 +160,16 @@ class MemcachedCache(BaseMemcachedCache):
key
=
self
.
make_key
(
key
,
version
=
version
)
key
=
self
.
make_key
(
key
,
version
=
version
)
return
self
.
_cache
.
touch
(
key
,
self
.
get_backend_timeout
(
timeout
))
!=
0
return
self
.
_cache
.
touch
(
key
,
self
.
get_backend_timeout
(
timeout
))
!=
0
def
get
(
self
,
key
,
default
=
None
,
version
=
None
):
key
=
self
.
make_key
(
key
,
version
=
version
)
val
=
self
.
_cache
.
get
(
key
)
# python-memcached doesn't support default values in get().
# https://github.com/linsomniac/python-memcached/issues/159
# Remove this method if that issue is fixed.
if
val
is
None
:
return
default
return
val
class
PyLibMCCache
(
BaseMemcachedCache
):
class
PyLibMCCache
(
BaseMemcachedCache
):
"An implementation of a cache binding using pylibmc"
"An implementation of a cache binding using pylibmc"
...
...
tests/cache/tests.py
Dosyayı görüntüle @
0104b5a4
...
@@ -274,6 +274,11 @@ class BaseCacheTests:
...
@@ -274,6 +274,11 @@ class BaseCacheTests:
cache
.
set
(
"key"
,
"value"
)
cache
.
set
(
"key"
,
"value"
)
self
.
assertEqual
(
cache
.
get
(
"key"
),
"value"
)
self
.
assertEqual
(
cache
.
get
(
"key"
),
"value"
)
def
test_default_used_when_none_is_set
(
self
):
"""If None is cached, get() returns it instead of the default."""
cache
.
set
(
'key_default_none'
,
None
)
self
.
assertIsNone
(
cache
.
get
(
'key_default_none'
,
default
=
'default'
))
def
test_add
(
self
):
def
test_add
(
self
):
# A key can be added to a cache
# A key can be added to a cache
cache
.
add
(
"addkey1"
,
"value"
)
cache
.
add
(
"addkey1"
,
"value"
)
...
@@ -1365,6 +1370,14 @@ class MemcachedCacheTests(BaseMemcachedTests, TestCase):
...
@@ -1365,6 +1370,14 @@ class MemcachedCacheTests(BaseMemcachedTests, TestCase):
def
test_memcached_options
(
self
):
def
test_memcached_options
(
self
):
self
.
assertEqual
(
cache
.
_cache
.
server_max_value_length
,
9999
)
self
.
assertEqual
(
cache
.
_cache
.
server_max_value_length
,
9999
)
def
test_default_used_when_none_is_set
(
self
):
"""
python-memcached doesn't support default in get() so this test
overrides the one in BaseCacheTests.
"""
cache
.
set
(
'key_default_none'
,
None
)
self
.
assertEqual
(
cache
.
get
(
'key_default_none'
,
default
=
'default'
),
'default'
)
@unittest.skipUnless
(
PyLibMCCache_params
,
"PyLibMCCache backend not configured"
)
@unittest.skipUnless
(
PyLibMCCache_params
,
"PyLibMCCache backend not configured"
)
@override_settings
(
CACHES
=
caches_setting_for_tests
(
@override_settings
(
CACHES
=
caches_setting_for_tests
(
...
...
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