Skip to content

Commit

Permalink
Fix #69: Better explain when expired TTLCache items are actually remo…
Browse files Browse the repository at this point in the history
…ved.
  • Loading branch information
tkem committed May 11, 2018
1 parent 396edb9 commit 7bb48e4
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions docs/index.rst
Expand Up @@ -81,26 +81,24 @@ of one argument used to retrieve the size of an item's value.

This class associates a time-to-live value with each item. Items
that expire because they have exceeded their time-to-live will be
removed automatically. If no expired items are there to remove,
the least recently used items will be discarded first to make space
when necessary. Trying to access an expired item will raise a
:exc:`KeyError`.
no longer accessible, and will be removed eventually. If no
expired items are there to remove, the least recently used items
will be discarded first to make space when necessary.

By default, the time-to-live is specified in seconds, and the
:func:`time.time` function is used to retrieve the current time. A
custom `timer` function can be supplied if needed.

.. method:: expire(self, time=None)

Since expired items will be "physically" removed from a cache
only at the next mutating operation, e.g. :meth:`__setitem__` or
:meth:`__delitem__`, to avoid changing the underlying dictionary
while iterating over it, expired items may still claim memory
although they are no longer accessible. Calling this method
removes all items whose time-to-live would have expired by
`time`, so garbage collection is free to reuse their memory. If
`time` is :const:`None`, this removes all items that have
expired by the current value returned by :attr:`timer`.
Expired items will be removed from a cache only at the next
mutating operation, e.g. :meth:`__setitem__` or
:meth:`__delitem__`, and therefore may still claim memory.
Calling this method removes all items whose time-to-live would
have expired by `time`, so garbage collection is free to reuse
their memory. If `time` is :const:`None`, this removes all
items that have expired by the current value returned by
:attr:`timer`.


Extending cache classes
Expand Down

0 comments on commit 7bb48e4

Please sign in to comment.