cache_mysql#
Source code: sensai/util/cache_mysql.py
- class MySQLPersistentKeyValueCache(host: str, db: str, user: str, pw: str, value_type: ValueType, table_name='cache', connect_params: Optional[dict] = None, in_memory=False, max_key_length: int = 255, port=3306)[source]#
Bases:
PersistentKeyValueCache
Can cache arbitrary values in a MySQL database. The keys are always strings at the database level, i.e. if a key is not a string, it is converted to a string using str().
- Parameters:
host –
db –
user –
pw –
value_type – the type of value to store in the cache
table_name –
connect_params – additional parameters to pass to the pymysql.connect() function (e.g. ssl, etc.)
in_memory –
max_key_length – maximal length of the cache key string (keys are always strings) stored in the DB (i.e. the MySQL type is VARCHAR[max_key_length])
port – the MySQL server port to connect to
- class ValueType(value)[source]#
Bases:
Enum
The value type to use within the MySQL database. Note that the binary BLOB types can be used for all Python types that can be pickled, so the lack of specific types (e.g. for strings) is not a problem.
- DOUBLE = ('DOUBLE', False)#
- BLOB = ('BLOB', True)#
for Python data types whose pickled representation is up to 64 KB
- MEDIUMBLOB = ('MEDIUMBLOB', True)#
for Python data types whose pickled representation is up to 16 MB