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
a027447f
Kaydet (Commit)
a027447f
authored
Kas 06, 2016
tarafından
Olivier Tabone
Kaydeden (comit)
Tim Graham
Eyl 06, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #27318 -- Made cache.set_many() return the list of failed keys.
üst
407c1249
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
36 additions
and
6 deletions
+36
-6
AUTHORS
AUTHORS
+1
-0
base.py
django/core/cache/backends/base.py
+4
-0
memcached.py
django/core/cache/backends/memcached.py
+8
-5
2.0.txt
docs/releases/2.0.txt
+2
-1
cache.txt
docs/topics/cache.txt
+7
-0
tests.py
tests/cache/tests.py
+14
-0
No files found.
AUTHORS
Dosyayı görüntüle @
a027447f
...
...
@@ -609,6 +609,7 @@ answer newbie questions, and generally made Django that much better:
Oliver Beattie <oliver@obeattie.com>
Oliver Rutherfurd <http://rutherfurd.net/>
Olivier Sels <olivier.sels@gmail.com>
Olivier Tabone <olivier.tabone@ripplemotion.fr>
Orestis Markou <orestis@orestis.gr>
Orne Brocaar <http://brocaar.com/>
Oscar Ramirez <tuxskar@gmail.com>
...
...
django/core/cache/backends/base.py
Dosyayı görüntüle @
a027447f
...
...
@@ -206,9 +206,13 @@ class BaseCache:
If timeout is given, use that timeout for the key; otherwise use the
default cache timeout.
On backends that support it, return a list of keys that failed
insertion, or an empty list if all keys were inserted successfully.
"""
for
key
,
value
in
data
.
items
():
self
.
set
(
key
,
value
,
timeout
=
timeout
,
version
=
version
)
return
[]
def
delete_many
(
self
,
keys
,
version
=
None
):
"""
...
...
django/core/cache/backends/memcached.py
Dosyayı görüntüle @
a027447f
...
...
@@ -134,11 +134,14 @@ class BaseMemcachedCache(BaseCache):
return
val
def
set_many
(
self
,
data
,
timeout
=
DEFAULT_TIMEOUT
,
version
=
None
):
safe_data
=
{
self
.
make_key
(
key
,
version
=
version
):
value
for
key
,
value
in
data
.
items
()
}
self
.
_cache
.
set_multi
(
safe_data
,
self
.
get_backend_timeout
(
timeout
))
safe_data
=
{}
original_keys
=
{}
for
key
,
value
in
data
.
items
():
safe_key
=
self
.
make_key
(
key
,
version
=
version
)
safe_data
[
safe_key
]
=
value
original_keys
[
safe_key
]
=
key
failed_keys
=
self
.
_cache
.
set_multi
(
safe_data
,
self
.
get_backend_timeout
(
timeout
))
return
[
original_keys
[
k
]
for
k
in
failed_keys
]
def
delete_many
(
self
,
keys
,
version
=
None
):
self
.
_cache
.
delete_multi
(
self
.
make_key
(
key
,
version
=
version
)
for
key
in
keys
)
...
...
docs/releases/2.0.txt
Dosyayı görüntüle @
a027447f
...
...
@@ -157,7 +157,8 @@ Minor features
Cache
~~~~~
* ...
* On memcached, ``cache.set_many()`` returns a list of keys that failed to be
inserted.
CSRF
~~~~
...
...
docs/topics/cache.txt
Dosyayı görüntüle @
a027447f
...
...
@@ -881,6 +881,13 @@ of key-value pairs::
Like ``cache.set()``, ``set_many()`` takes an optional ``timeout`` parameter.
On supported backends (memcached), ``set_many()`` returns a list of keys that
failed to be inserted.
.. versionchanged:: 2.0
The return value containing list of failing keys was added.
You can delete keys explicitly with ``delete()``. This is an easy way of
clearing the cache for a particular object::
...
...
tests/cache/tests.py
Dosyayı görüntüle @
a027447f
...
...
@@ -470,6 +470,11 @@ class BaseCacheTests:
self
.
assertEqual
(
cache
.
get
(
"key1"
),
"spam"
)
self
.
assertEqual
(
cache
.
get
(
"key2"
),
"eggs"
)
def
test_set_many_returns_empty_list_on_success
(
self
):
"""set_many() returns an empty list when all keys are inserted."""
failing_keys
=
cache
.
set_many
({
'key1'
:
'spam'
,
'key2'
:
'eggs'
})
self
.
assertEqual
(
failing_keys
,
[])
def
test_set_many_expiration
(
self
):
# set_many takes a second ``timeout`` parameter
cache
.
set_many
({
"key1"
:
"spam"
,
"key2"
:
"eggs"
},
1
)
...
...
@@ -1239,6 +1244,13 @@ class BaseMemcachedTests(BaseCacheTests):
finally
:
signals
.
request_finished
.
connect
(
close_old_connections
)
def
test_set_many_returns_failing_keys
(
self
):
def
fail_set_multi
(
mapping
,
*
args
,
**
kwargs
):
return
mapping
.
keys
()
with
mock
.
patch
(
'
%
s.Client.set_multi'
%
self
.
client_library_name
,
side_effect
=
fail_set_multi
):
failing_keys
=
cache
.
set_many
({
'key'
:
'value'
})
self
.
assertEqual
(
failing_keys
,
[
'key'
])
@unittest.skipUnless
(
MemcachedCache_params
,
"MemcachedCache backend not configured"
)
@override_settings
(
CACHES
=
caches_setting_for_tests
(
...
...
@@ -1247,6 +1259,7 @@ class BaseMemcachedTests(BaseCacheTests):
))
class
MemcachedCacheTests
(
BaseMemcachedTests
,
TestCase
):
base_params
=
MemcachedCache_params
client_library_name
=
'memcache'
def
test_memcached_uses_highest_pickle_version
(
self
):
# Regression test for #19810
...
...
@@ -1270,6 +1283,7 @@ class MemcachedCacheTests(BaseMemcachedTests, TestCase):
))
class
PyLibMCCacheTests
(
BaseMemcachedTests
,
TestCase
):
base_params
=
PyLibMCCache_params
client_library_name
=
'pylibmc'
# libmemcached manages its own connections.
should_disconnect_on_close
=
False
...
...
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