Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
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
cpython
Commits
02566ec8
Kaydet (Commit)
02566ec8
authored
Eyl 04, 2010
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Adopt more descriptive attribute names as suggested on python-dev.
üst
e9a4de51
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
23 deletions
+23
-23
functools.rst
Doc/library/functools.rst
+3
-3
3.2.rst
Doc/whatsnew/3.2.rst
+3
-3
functools.py
Lib/functools.py
+6
-6
re.py
Lib/re.py
+2
-2
test_functools.py
Lib/test/test_functools.py
+9
-9
No files found.
Doc/library/functools.rst
Dosyayı görüntüle @
02566ec8
...
...
@@ -47,12 +47,12 @@ The :mod:`functools` module defines the following functions:
results, the positional and keyword arguments to the function must be
hashable.
The wrapped function is instrumented with two attributes, :attr:`hits`
and :attr:`misses` which count the number of successful or unsuccessful
The wrapped function is instrumented with two attributes, :attr:`
cache_
hits`
and :attr:`
cache_
misses` which count the number of successful or unsuccessful
cache lookups. These statistics are helpful for tuning the *maxsize*
parameter and for measuring the cache's effectiveness.
The wrapped function also has a :attr:`clear` attribute which can be
The wrapped function also has a :attr:`c
ache_c
lear` attribute which can be
called (with no arguments) to clear the cache.
The original underlying function is accessible through the
...
...
Doc/whatsnew/3.2.rst
Dosyayı görüntüle @
02566ec8
...
...
@@ -85,17 +85,17 @@ New, Improved, and Deprecated Modules
return c.fetchone()[0]
To help with choosing an effective cache size, the wrapped function is
instrumented with two attributes *
hits* and *
misses*::
instrumented with two attributes *
cache_hits* and *cache_
misses*::
>>> for name in user_requests:
... get_phone_number(name)
>>> print(get_phone_number.
hits, get_phone_number.
misses)
>>> print(get_phone_number.
cache_hits, get_phone_number.cache_
misses)
4805 980
If the phonelist table gets updated, the outdated contents of the cache can be
cleared with::
>>> get_phone_number.clear()
>>> get_phone_number.c
ache_c
lear()
(Contributed by Raymond Hettinger)
...
...
Lib/functools.py
Dosyayı görüntüle @
02566ec8
...
...
@@ -142,23 +142,23 @@ def lru_cache(maxsize=100):
with
lock
:
result
=
cache
[
key
]
cache_renew
(
key
)
# record recent use of this key
wrapper
.
hits
+=
1
wrapper
.
cache_
hits
+=
1
except
KeyError
:
result
=
user_function
(
*
args
,
**
kwds
)
with
lock
:
cache
[
key
]
=
result
# record recent use of this key
wrapper
.
misses
+=
1
wrapper
.
cache_
misses
+=
1
if
len
(
cache
)
>
maxsize
:
cache_popitem
(
0
)
# purge least recently used cache entry
return
result
def
clear
():
def
c
ache_c
lear
():
"""Clear the cache and cache statistics"""
with
lock
:
cache
.
clear
()
wrapper
.
hits
=
wrapper
.
misses
=
0
wrapper
.
cache_hits
=
wrapper
.
cache_
misses
=
0
wrapper
.
hits
=
wrapper
.
misses
=
0
wrapper
.
c
lear
=
clear
wrapper
.
cache_hits
=
wrapper
.
cache_
misses
=
0
wrapper
.
c
ache_clear
=
cache_
clear
return
wrapper
return
decorating_function
Lib/re.py
Dosyayı görüntüle @
02566ec8
...
...
@@ -207,8 +207,8 @@ def compile(pattern, flags=0):
def
purge
():
"Clear the regular expression caches"
_compile_typed
.
clear
()
_compile_repl
.
clear
()
_compile_typed
.
c
ache_c
lear
()
_compile_repl
.
c
ache_c
lear
()
def
template
(
pattern
,
flags
=
0
):
"Compile a template pattern, returning a pattern object"
...
...
Lib/test/test_functools.py
Dosyayı görüntüle @
02566ec8
...
...
@@ -508,21 +508,21 @@ class TestLRU(unittest.TestCase):
actual
=
f
(
x
,
y
)
expected
=
orig
(
x
,
y
)
self
.
assertEquals
(
actual
,
expected
)
self
.
assert_
(
f
.
hits
>
f
.
misses
)
self
.
assertEquals
(
f
.
hits
+
f
.
misses
,
1000
)
self
.
assert_
(
f
.
cache_hits
>
f
.
cache_
misses
)
self
.
assertEquals
(
f
.
cache_hits
+
f
.
cache_
misses
,
1000
)
f
.
clear
()
# test clearing
self
.
assertEqual
(
f
.
hits
,
0
)
self
.
assertEqual
(
f
.
misses
,
0
)
f
.
c
ache_c
lear
()
# test clearing
self
.
assertEqual
(
f
.
cache_
hits
,
0
)
self
.
assertEqual
(
f
.
cache_
misses
,
0
)
f
(
x
,
y
)
self
.
assertEqual
(
f
.
hits
,
0
)
self
.
assertEqual
(
f
.
misses
,
1
)
self
.
assertEqual
(
f
.
cache_
hits
,
0
)
self
.
assertEqual
(
f
.
cache_
misses
,
1
)
# Test bypassing the cache
self
.
assertIs
(
f
.
__wrapped__
,
orig
)
f
.
__wrapped__
(
x
,
y
)
self
.
assertEqual
(
f
.
hits
,
0
)
self
.
assertEqual
(
f
.
misses
,
1
)
self
.
assertEqual
(
f
.
cache_
hits
,
0
)
self
.
assertEqual
(
f
.
cache_
misses
,
1
)
# test size zero (which means "never-cache")
@functools.lru_cache
(
0
)
...
...
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