cacheblob.handlers package

Submodules

cacheblob.handlers.gzip module

This module implements a gzip handler. It stores item values as gzip files on disk and uses a SQLite database to store the metadata. This is most convenient if you are using items as files in another way, or otherwise prefer being able to interact with each item as a file, and each one is large enough to benefit from compression.

class cacheblob.handlers.gzip.Gzip(opts=None)[source]

Bases: cacheblob.handlers.plaintext.Plaintext

This class implements a handler which stores items as gzip files on disk, with a SQLite database used for the indexing.

cacheblob.handlers.handler module

This module provides base handler functions, and basic functionality. Will successfully operate as a handler, but if used as one will only store data in-memory.

class cacheblob.handlers.handler.Handler(opts=None)[source]

Bases: object

This module represents a handler for cacheblob.item objects. Handlers offer simple fetch() and store() capabilities, and other utilities. Items included are expected to be unique by index.

close()[source]

Close any associated databases. For this default handler, this does nothing.

fetch(index)[source]

Fetch an item from the handler.

Parameters:index – Index of the item to fetch. Indexes are expected to be unique at any given time.
Returns:The item, or None if no unexpired items are found.
fetch_all()[source]

Fetch all of the items and return an iterator. Note that this function does not guarantee that the items will not be modified between this function returning and the user accessing the values.

Returns:An iterator that yields items.
fetch_all_with_status()[source]

Fetch all of the items and return an iterator. Note that this function does not guarantee that the items will not be modified between this function returning and the user accessing the values. This differs from fetch_all() because it will also return whether or not an item was found, which differs in the case of expired items.

Returns:An iterator that yields pairs of items and their status.
fetch_with_status(index)[source]

Fetch an item from the handler. This differs from fetch() because it will also return whether or not an item was found, which differs in the case of expired items.

Parameters:index – Index of the item to fetch. Indexes are expected to be unique at any given time.
Returns:The item, or None if no unexpired items are found, and whether an item was found.
get_indexes()[source]

Get all of the indexes stored in the handler.

Returns:The list of indexes.
may_purge_if_expired

Returns whether or not expired items may be purged from the underlying persistent data store. Note that this does not guarantee that they will be purged, but instead allows them to be purged.

Returns:Whether items may be purged if they are expired.
memoize

Get the memoization status.

Returns:Whether or not in-memory memoization is enabled.
memoize_max_entries

Get the max number of memoized items at a given time.

Returns:The maximum number of items that will be memoized.
memoize_max_length

Get the max value length allowed for memoized items.

Returns:The maximum value length allowed for items memoized.
overwrite

Get the overwrite status.

Returns:Whether or not the object will overwrite entries with the same index.
purge(index)[source]

Purge an item from the handler. The persistent value will be removed.

Parameters:index – The index of the item to be purged.
Returns:Whether or not an item was removed.
purge_any_expired()[source]

Purge any items that can be purged, based on their expiry.

Returns:Count of items purged.
purge_if_expired(index)[source]

If an item is expired, purge it.

Parameters:index – The index of the item to be purged.
Returns:Whether or not an item was removed.
store(*args, **kwargs)[source]
Store an entry in the handler. Parameters can be either a CacheItem
or parameters to create one
Parameters:
  • args|item – a CacheItem object, or arguments to create one.
  • kwargs – Keyword arguments to create a CacheItem object.
cacheblob.handlers.handler.is_number(value)[source]

Return if value is numeric, based on attempting to coerce to float.

Parameters:value – The value in question.
Returns:True if the float(value) does not throw an exception, otherwise False.

cacheblob.handlers.mongo module

This module implements a MongoDB handler. It stores the items in a MongoDB database.

class cacheblob.handlers.mongo.Mongo(opts=None)[source]

Bases: cacheblob.handlers.handler.Handler

This class implements a MongoDB handler. It stores the items in a MongoDB database.

client

Get the MongoDB client in use.

Returns:The MongoDB client.
close()[source]

Close the database.

database

Get the database in use. This is an internal utility that is not designed to be called by users.

Returns:The database.
database_name

Get the database name in use.

Returns:The database name.
fetch(index)[source]

Fetch an item from the handler.

Parameters:index – Index of the item to fetch. Indexes are expected to be unique at any given time.
Returns:The item, or None if no unexpired items are found.
fetch_all()[source]

Fetch all of the items and return an iterator. Note that this function does not guarantee that the items will not be modified between this function returning and the user accessing the values.

Returns:An iterator that yields items.
fetch_all_with_status()[source]

Fetch all of the items and return an iterator. Note that this function does not guarantee that the items will not be modified between this function returning and the user accessing the values. This differs from fetch_all() because it will also return whether or not an item was found, which differs in the case of expired items.

Returns:An iterator that yields pairs of items and their status.
fetch_with_status(index)[source]

Fetch an item from the handler. This differs from fetch() because it will also return whether or not an item was found, which differs in the case of expired items.

Parameters:index – Index of the item to fetch. Indexes are expected to be unique at any given time.
Returns:The item, or None if no unexpired items are found, and whether an item was found.
get_indexes()[source]

Get all of the indexes stored in the handler.

Returns:The list of indexes.
open_database()[source]

Open the mongo database and collection that will contain our items.

Returns:True if the client could create the database and collection, otherwise None.
purge(index)[source]

Purge an item from the handler. The persistent value will be removed.

Parameters:index – The index of the item to be purged.
Returns:Whether or not an item was removed.
table

Get the MongoDB table in use.

Returns:The table.
table_name

Get the table name in use.

Returns:The table name.

cacheblob.handlers.plaintext module

This module implements a plaintext handler. It stores item values in files on disk and uses a SQLite database to store the metadata. This is most convenient if you are using items as files in another way, or otherwise prefer being able to interact with each item as a file.

class cacheblob.handlers.plaintext.Plaintext(opts=None)[source]

Bases: cacheblob.handlers.handler.Handler

This class implements a plaintext handler which stores items as files on disk, with a SQLite database used for the indexing.

close()[source]

Close the database.

database

Get the database in use. This is an internal utility that is not designed to be called by users.

Returns:The database.
define_index(directory=None, index_file=None)[source]

Define the full index file path, based on the directory and index_file. The directory and index_file need not be provided here, if previously defined.

Parameters:
  • directory – The directory to use.
  • index_file – The SQLite file to use for item metadata.
directory

Get the directory in which the item files and SQLite index database are stored.

Returns:The directory used.
fetch(index)[source]

Fetch an item from the handler.

Parameters:index – Index of the item to fetch. Indexes are expected to be unique at any given time.
Returns:The item, or None if no unexpired items are found.
fetch_all()[source]

Fetch all of the items and return an iterator. Note that this function does not guarantee that the items will not be modified between this function returning and the user accessing the values.

Returns:An iterator that yields items.
fetch_all_with_status()[source]

Fetch all of the items and return an iterator. Note that this function does not guarantee that the items will not be modified between this function returning and the user accessing the values. This differs from fetch_all() because it will also return whether or not an item was found, which differs in the case of expired items.

Returns:An iterator that yields pairs of items and their status.
fetch_with_status(index)[source]

Fetch an item from the handler. This differs from fetch() because it will also return whether or not an item was found, which differs in the case of expired items.

Parameters:index – Index of the item to fetch. Indexes are expected to be unique at any given time.
Returns:The item, or None if no unexpired items are found, and whether an item was found.
get_indexes()[source]

Get all of the indexes stored in the handler.

Returns:The list of indexes.
index_file

Get the filename of the SQLite database for storing item metadata.

Returns:The name of the index file.
open_database()[source]

Open the SQLite database that will be used to store the metadata.

purge(index)[source]

Purge an item from the handler. The persistent value will be removed.

Parameters:index – The index of the item to be purged.
Returns:Whether or not an item was removed.

cacheblob.handlers.sqlite module

This module implements a SQLite handler. It stores items in a SQLite database.

class cacheblob.handlers.sqlite.SQLite(opts=None)[source]

Bases: cacheblob.handlers.handler.Handler

This class implements a SQLite handler which stores items in a SQLite database,

close()[source]

Close the database.

database

Get the database in use. This is an internal utility that is not designed to be called by users.

Returns:The database.
define_index(directory=None, index_file=None)[source]

Define the full index file path, based on the directory and index_file. The directory and index_file need not be provided here, if previously defined.

Parameters:
  • directory – The directory to use.
  • index_file – The SQLite file to use for items.
directory

Get the directory in which the SQLite database is stored.

Returns:The directory used.
fetch(index)[source]

Fetch an item from the handler.

Parameters:index – Index of the item to fetch. Indexes are expected to be unique at any given time.
Returns:The item, or None if no unexpired items are found.
fetch_all()[source]

Fetch all of the items and return an iterator. Note that this function does not guarantee that the items will not be modified between this function returning and the user accessing the values.

Returns:An iterator that yields items.
fetch_all_with_status()[source]

Fetch all of the items and return an iterator. Note that this function does not guarantee that the items will not be modified between this function returning and the user accessing the values. This differs from fetch_all() because it will also return whether or not an item was found, which differs in the case of expired items.

Returns:An iterator that yields pairs of items and their status.
fetch_with_status(index)[source]

Fetch an item from the handler. This differs from fetch() because it will also return whether or not an item was found, which differs in the case of expired items.

Parameters:index – Index of the item to fetch. Indexes are expected to be unique at any given time.
Returns:The item, or None if no unexpired items are found, and whether an item was found.
get_indexes()[source]

Get all of the indexes stored in the handler.

Returns:The list of indexes.
index_file

Get the filename of the SQLite database for storing items.

Returns:The name of the index file.
open_database()[source]

Open the SQLite database that will be used to store the metadata.

purge(index)[source]

Purge an item from the handler. The persistent value will be removed.

Parameters:index – The index of the item to be purged.
Returns:Whether or not an item was removed.

Module contents