cacheblob package¶
Subpackages¶
Submodules¶
cacheblob.cache module¶
This module implements a factory for the easy generation of handlers, identified by strings.
-
class
cacheblob.cache.
Cacheblob
[source]¶ Bases:
object
This class implements a factory to generate the right type of hander, such that the user does not need to know the module paths.
-
static
cache
(handler='handler', *args, **kwargs)[source]¶ Create a handler from the given type requested.
Parameters: - handler – The string name of a handler type. Must be one of: handler, gzip, plaintext, sqlite, mongo.
- args – Other arguments to pass through to handler.
- kwargs – Keyword arguments to pass through to handler.
Returns: A handler of the given type.
-
static
cacheblob.cli module¶
CacheBlob CLI interface. Fetch or purge items.
- Usage:
- cli.py (fetch|purge|purge_any_expired) [INDEX ...] cli.py –handler=sqlite (fetch|purge|purge_any_expired) [INDEX ...] cli.py –handler=gzip –index_file=index.db (fetch|purge|purge_any_expired) [INDEX ...] cli.py –handler=plaintext –directory=data (fetch|purge|purge_any_expired) [INDEX ...]
- Options:
- -h –help Show this screen. –version Show version. –handler=<sqlite> Handler type [default: sqlite] –directory=<data> Directory if applicable [default: data] –index_file=<index.db> Index file if applicable [default: index.db]
If no arguments are specified to fetch, all INDEX are fetched. Purge, however, will not let you purge everything that easily.
cacheblob.constants module¶
This module contains constants and default values
cacheblob.db_wrapper module¶
This module allows us to manage a series of tables in a SQLite database.
-
class
cacheblob.db_wrapper.
DBWrapper
(name='results.db', pytypes=False)[source]¶ Bases:
object
DBWrapper manages a series of DBWrapperTable objects.
-
add_table
(table_name)[source]¶ Add a table to the collection.
Parameters: table_name – The name you will refer to the table by.
-
init_table
(table_name, create_sql)[source]¶ Initialize a table.
Parameters: - table_name – The name you will refer to the table by.
- create_sql – The SQL used to initialize the database.
-
num_rows
(table_name)[source]¶ Count the number of rows in the table.
Parameters: table_name – The name of the table. Returns: Number of rows in the table.
-
print_db
(table_name)[source]¶ Print the contents of a table.
Parameters: table_name – The name of the table.
-
cacheblob.db_wrapper_table module¶
This modules provides a clean interface for handling a table in a SQLite database.
-
class
cacheblob.db_wrapper_table.
DBWrapperTable
(con, table_name='transactions')[source]¶ Bases:
object
This class provides utilities for creating and accessing a SQLite table
-
init_db
(create_sql)[source]¶ Initialize the database.
Parameters: create_sql – SQL to create the database.
-
cacheblob.item module¶
This module defines the CacheItem class, which represents key-value pairs that have an associated time of expiry.
-
class
cacheblob.item.
CacheItem
(index, value, created=None, expiry=None, duration=None)[source]¶ Bases:
object
This class represents items, which are key-value pairs that have an associated time of expiry.
cacheblob.CacheItem
-
created
¶ Access the creation time of the key-value pair, which is stored in UTC.
Returns: The creation time of the key-value pair.
-
duration
¶ Access the duration of the key-value pair. This is the length of time that the pair was intended to live for.
Returns: The duration of the key-value pair.
-
expiry
¶ Access the expiry time of the key-value pair, which is stored in UTC.
Returns: The expiry time of the key-value pair.
-
index
¶ Access the index, or key, of a key-value pair.
Returns: The index, or key, of the key-value pair.
-
is_expired
¶ Determine whether or not the item is expired.
Returns: Whether the item is currently expired or not.
-
length
¶ Access the length of the item’s value. If the item was a string type then this will be the length of the string. Otherwise this will be None, which does not indicate that the item has no value.
Returns: The length of the item’s value.
-
updated
¶ Access the last update time of the item.
Returns: When the item was updated, in UTC.
-
value
¶ Access the value of a key-value pair.
Returns: The value of the key-value pair.
-