cacheblob package

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.

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.cli.main()[source]

Main CLI handler.

Returns:0 on success, exits with message otherwise.

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.
close_db()[source]

Commit results to database and close the database.

empty_all_dbs()[source]

Empty all of the tables.

empty_db(table_name)[source]

Empty a given table.

Parameters:table_name – The name of the table.
get_con()[source]

Access or initiate the sqlite3 connection.

Returns:The sqlite3 connection.
get_cursor()[source]

Access or initiate the sqlite3 cursor.

Returns:The sqlite3 cursor.
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.
set_update_sql(table_name, update_sql)[source]

Set the update SQL to be used for update_db for a given table. Be careful, no security checks in place here.

Parameters:
  • table_name – The name of the table.
  • update_sql – The SQL to be used for an update.
update_db(table_name, params)[source]

Update the database with the template provided earlier in set_update_sql().

Parameters:
  • table_name – The name of the table.
  • params – The list of SQL parameters.

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

close_db()[source]

Commit results to database and close the database.

empty_db()[source]

Empty the database.

get_con()[source]

Get the connection object.

Returns:The connection object.
get_cursor()[source]

Get the database cursor.

Returns:The cursor object
init_db(create_sql)[source]

Initialize the database.

Parameters:create_sql – SQL to create the database.
num_rows()[source]

Count the number of rows in the table.

Returns:Number of rows in the table.
print_db()[source]

Print the contents of the table.

set_update_sql(update_sql)[source]

Set the update SQL to be used for update_db. Be careful, no security checks in place here.

Parameters:update_sql – The SQL to be used for an update.
update_db(params)[source]

Update the database with the template provided earlier in set_update_sql().

Parameters:params – The list of SQL parameters.

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.

Module contents