API

ticktock.DEFAULT_MAXSIZE

The default maximum size used in LRU container size management. Currently, the default is 300.

ticktock.DEFAULT_TIMEOUT

The default timeout value used in data expiration. Currently, the default is 300 (5 minutes).

class ticktock.LRUShelf(dict, protocol=None, writeback=False, keyencoding='utf-8', maxsize=300)[source]

A Shelf with LRU cache management.

Note

The keyencoding keyword argument is only used in Python 3.

maxsize The maximum size allowed by the LRU cache management features. This can be changed directly.

class ticktock.TimeoutShelf(dict, protocol=None, writeback=False, keyencoding='utf-8', timeout=300)[source]

A Shelf with automatic data timeout.

Note

The keyencoding keyword argument is only used in Python 3.

timeout The default timeout value in seconds for this container. This value can be changed directly. It can also be overridden as needed by calling settimeout().

set(self, key, func, *args, **kwargs)

Return key’s value if it exists, otherwise call given function.

Parameters:
  • key – The key to lookup/set.
  • func – A function to use if the key doesn’t exist.

All other arguments and keyword arguments are passed to func.

settimeout(self, key, value, timeout)

Set a key with a timeout value (in seconds).

settimeout() is used to override the shelf’s timeout value.

Parameters:timeout (integer) – The timeout value in seconds for the given key. 0 means that the key will never expire.
sync(self)

Sync the timeout index entry with the shelf.

class ticktock.LRUTimeoutShelf(dict, protocol=None, writeback=False, keyencoding='utf-8', maxsize=300, timeout=300)[source]

A Shelf with LRU cache management and data timeout.

Note

The keyencoding keyword argument is only used in Python 3.

maxsize The maximum size allowed by the LRU cache management features. This can be changed directly.

timeout The default timeout value in seconds for this container. This value can be changed directly. It can also be overridden as needed by calling settimeout().

set(self, key, func, *args, **kwargs)

Return key’s value if it exists, otherwise call given function.

Parameters:
  • key – The key to lookup/set.
  • func – A function to use if the key doesn’t exist.

All other arguments and keyword arguments are passed to func.

settimeout(self, key, value, timeout)

Set a key with a timeout value (in seconds).

settimeout() is used to override the shelf’s timeout value.

Parameters:timeout (integer) – The timeout value in seconds for the given key. 0 means that the key will never expire.
sync(self)

Sync the timeout index entry with the shelf.

ticktock.open(filename, flag='c', protocol=None, writeback=False, maxsize=300, timeout=300)[source]

Open a database file as a persistent dictionary.

The persistent dictionary file is opened using dbm.open(), so performance will depend on which dbm modules are installed.

open() chooses to open a Shelf, LRUShelf, TimeoutShelf, or LRUTimeoutShelf depending on the values of keyword arguments maxsize and timeout. A None value for maxsize and timeout will disable the LRU cache management and automatic data timeout features respectively.

Parameters:
  • filename – The base filename for the underlying database that is passed to dbm.open().
  • flag – The flag to pass to dbm.open().
  • protocol – The pickle protocol to pass to pickle.dump().
  • writeback (bool) – Whether or not to write back all accessed entries on Shelf.sync and Shelf.close
  • maxsize (integer or None) – The maximum size the container is allowed to grow to. 0 means that no size limit is enforced. None means that LRU cache management is disabled.
  • timeout (integer or None) – The default timeout value for data (in seconds). 0 means that the data never expires. None means that automatic timeout features will be disabled.
Returns:

A shelf

Return type:

Shelf, LRUShelf, TimeoutShelf, or LRUTimeoutShelf

Previous topic

Quickstart

This Page