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
aed05eb6
Kaydet (Commit)
aed05eb6
authored
Agu 02, 2010
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Demonstrate the caching decorators in whatsnew.
üst
c8dc62d6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
0 deletions
+32
-0
3.2.rst
Doc/whatsnew/3.2.rst
+32
-0
No files found.
Doc/whatsnew/3.2.rst
Dosyayı görüntüle @
aed05eb6
...
...
@@ -66,6 +66,38 @@ Some smaller changes made to the core Python language are:
New, Improved, and Deprecated Modules
=====================================
* The functools module now includes two new decorators for caching function
calls, :func:`functools.lru_cache` and :func:`functools.lfu_cache`. These can
save repeated queries to an external resource whenever the results are
expected to be the same.
For example, adding an LFU decorator to a database query function can save
database accesses for the most popular searches::
@functools.lfu_cache(maxsize=50)
def get_phone_number(name):
c = conn.cursor()
c.execute('SELECT phonenumber FROM phonelist WHERE name=?', (name,))
return c.fetchone()[0]
The LFU (least-frequently-used) cache gives best results when the distribution
of popular queries tends to remain the same over time. In contrast, the LRU
(least-recently-used) cache gives best results when the distribution changes
over time (for example, the most popular news articles change each day as
newer articles are added).
The two caching decorators can be composed (nested) to handle hybrid cases
that have both long-term access patterns and some short-term access trends.
For example, music searches can reflect both long-term patterns (popular
classics) and short-term trends (new releases)::
@functools.lfu_cache(maxsize=500)
@functools.lru_cache(maxsize=100)
def find_music(song):
...
(Contributed by Raymond Hettinger)
* The previously deprecated :func:`contextlib.nested` function has been
removed in favor of a plain :keyword:`with` statement which can
accept multiple context managers. The latter technique is faster
...
...
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