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
db2727f9
Kaydet (Commit)
db2727f9
authored
Tem 07, 2013
tarafından
Alex Gaynor
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
A few cleanups to capture the minimum amount of code in try/except blocks.
üst
126250a4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
10 deletions
+14
-10
locmem.py
django/core/cache/backends/locmem.py
+14
-10
No files found.
django/core/cache/backends/locmem.py
Dosyayı görüntüle @
db2727f9
...
...
@@ -9,16 +9,17 @@ except ImportError:
from
django.core.cache.backends.base
import
BaseCache
,
DEFAULT_TIMEOUT
from
django.utils.synch
import
RWLock
# Global in-memory store of cache data. Keyed by name, to provide
# multiple named local memory caches.
_caches
=
{}
_expire_info
=
{}
_locks
=
{}
class
LocMemCache
(
BaseCache
):
def
__init__
(
self
,
name
,
params
):
BaseCache
.
__init__
(
self
,
params
)
global
_caches
,
_expire_info
,
_locks
self
.
_cache
=
_caches
.
setdefault
(
name
,
{})
self
.
_expire_info
=
_expire_info
.
setdefault
(
name
,
{})
self
.
_lock
=
_locks
.
setdefault
(
name
,
RWLock
())
...
...
@@ -45,11 +46,11 @@ class LocMemCache(BaseCache):
exp
=
self
.
_expire_info
.
get
(
key
,
0
)
if
exp
is
None
or
exp
>
time
.
time
():
pickled
=
self
.
_cache
[
key
]
try
:
if
pickled
is
not
None
:
if
pickled
is
not
None
:
try
:
return
pickle
.
loads
(
pickled
)
except
pickle
.
PickleError
:
return
default
except
pickle
.
PickleError
:
return
default
with
self
.
_lock
.
writer
():
try
:
...
...
@@ -73,11 +74,12 @@ class LocMemCache(BaseCache):
self
.
validate_key
(
key
)
try
:
pickled
=
pickle
.
dumps
(
value
,
pickle
.
HIGHEST_PROTOCOL
)
with
self
.
_lock
.
writer
():
self
.
_set
(
key
,
pickled
,
timeout
)
except
pickle
.
PickleError
:
pass
else
:
with
self
.
_lock
.
writer
():
self
.
_set
(
key
,
pickled
,
timeout
)
def
incr
(
self
,
key
,
delta
=
1
,
version
=
None
):
value
=
self
.
get
(
key
,
version
=
version
)
if
value
is
None
:
...
...
@@ -86,10 +88,11 @@ class LocMemCache(BaseCache):
key
=
self
.
make_key
(
key
,
version
=
version
)
try
:
pickled
=
pickle
.
dumps
(
new_value
,
pickle
.
HIGHEST_PROTOCOL
)
with
self
.
_lock
.
writer
():
self
.
_cache
[
key
]
=
pickled
except
pickle
.
PickleError
:
pass
else
:
with
self
.
_lock
.
writer
():
self
.
_cache
[
key
]
=
pickled
return
new_value
def
has_key
(
self
,
key
,
version
=
None
):
...
...
@@ -138,6 +141,7 @@ class LocMemCache(BaseCache):
self
.
_cache
.
clear
()
self
.
_expire_info
.
clear
()
# For backwards compatibility
class
CacheClass
(
LocMemCache
):
pass
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