Skip to content

Commit ee7a248

Browse files
committed
Add docs about the eviction policy to recipes
1 parent f3fcdff commit ee7a248

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

diskcache/recipes.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class Averager:
1717
Sometimes known as "online statistics," the running average maintains the
1818
total and count. The average can then be calculated at any time.
1919
20+
Assumes the key will not be evicted. Set the eviction policy to 'none' on
21+
the cache to guarantee the key is not evicted.
22+
2023
>>> import diskcache
2124
>>> cache = diskcache.FanoutCache()
2225
>>> ave = Averager(cache, 'latency')
@@ -65,6 +68,9 @@ def pop(self):
6568
class Lock:
6669
"""Recipe for cross-process and cross-thread lock.
6770
71+
Assumes the key will not be evicted. Set the eviction policy to 'none' on
72+
the cache to guarantee the key is not evicted.
73+
6874
>>> import diskcache
6975
>>> cache = diskcache.Cache()
7076
>>> lock = Lock(cache, 'report-123')
@@ -113,6 +119,9 @@ def __exit__(self, *exc_info):
113119
class RLock:
114120
"""Recipe for cross-process and cross-thread re-entrant lock.
115121
122+
Assumes the key will not be evicted. Set the eviction policy to 'none' on
123+
the cache to guarantee the key is not evicted.
124+
116125
>>> import diskcache
117126
>>> cache = diskcache.Cache()
118127
>>> rlock = RLock(cache, 'user-123')
@@ -181,6 +190,9 @@ def __exit__(self, *exc_info):
181190
class BoundedSemaphore:
182191
"""Recipe for cross-process and cross-thread bounded semaphore.
183192
193+
Assumes the key will not be evicted. Set the eviction policy to 'none' on
194+
the cache to guarantee the key is not evicted.
195+
184196
>>> import diskcache
185197
>>> cache = diskcache.Cache()
186198
>>> semaphore = BoundedSemaphore(cache, 'max-cons', value=2)
@@ -251,6 +263,9 @@ def throttle(
251263
):
252264
"""Decorator to throttle calls to function.
253265
266+
Assumes keys will not be evicted. Set the eviction policy to 'none' on the
267+
cache to guarantee the keys are not evicted.
268+
254269
>>> import diskcache, time
255270
>>> cache = diskcache.Cache()
256271
>>> count = 0
@@ -305,6 +320,9 @@ def barrier(cache, lock_factory, name=None, expire=None, tag=None):
305320
306321
Supports different kinds of locks: Lock, RLock, BoundedSemaphore.
307322
323+
Assumes keys will not be evicted. Set the eviction policy to 'none' on the
324+
cache to guarantee the keys are not evicted.
325+
308326
>>> import diskcache, time
309327
>>> cache = diskcache.Cache()
310328
>>> @barrier(cache, Lock)

0 commit comments

Comments
 (0)