File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -294,6 +294,26 @@ Some users may defer all culling to a cron-like process by setting the
294294Each of these methods is designed to work concurrent to others. None of them
295295block readers or writers in other threads or processes.
296296
297+ Caches may be iterated by either insertion order or sorted order. The default
298+ ordering uses insertion order. To iterate by sorted order, use :meth: `iterkeys
299+ <.Cache.iterkeys> `. The sort order is determined by the database which makes it
300+ valid only for `str `, `bytes `, `int `, and `float ` data types. Other types of
301+ keys will be serialized which is likely to have a meaningless sorted order.
302+
303+ >>> for key in ' cab' :
304+ ... cache[key] = None
305+ >>> list (cache)
306+ ['c', 'a', 'b']
307+ >>> list (cache.iterkeys())
308+ ['a', 'b', 'c']
309+ >>> cache.peekitem()
310+ ('b', None)
311+ >>> cache.peekitem(last = False )
312+ ('c', None)
313+
314+ If only the first or last item in insertion order is desired then
315+ :meth: `peekitem <.Cache.peekitem> ` is more efficient than using iteration.
316+
297317Lastly, three methods support metadata about the cache. The first is
298318:meth: `volume <diskcache.Cache.volume> ` which returns the estimated total size
299319in bytes of the cache directory on disk.
You can’t perform that action at this time.
0 commit comments