baseplate.context.memcache
¶
Configuration Parsing¶
-
baseplate.context.memcache.
pool_from_config
(app_config, prefix=u'memcache.', serializer=None, deserializer=None)¶ Make a PooledClient from a configuration dictionary.
The keys useful to
pool_from_config()
should be prefixed, e.g.memcache.endpoint
,memcache.max_pool_size
, etc. Theprefix
argument specifies the prefix used to filter keys. Each key is mapped to a corresponding keyword argument on thePooledClient
constructor.Supported keys:
endpoint
(required): a string representing a host and port to connect- to memcached service, e.g.
localhost:11211
or127.0.0.1:11211
.
max_pool_size
: an integer for the maximum pool size to use, by default- this is
2147483648
.
connect_timeout
: a float representing seconds to wait for a connection to- memcached server. Defaults to the underlying socket default timeout.
timeout
: a float representing seconds to wait for calls on the- socket connected to memcache. Defaults to the underlying socket default timeout.
Parameters: - app_config (dict) – the config dictionary
- prefix (str) – prefix for config keys
- serializer (callable) – function to serialize values to strings suitable
for being stored in memcached. An example is
make_dump_and_compress_fn()
. - deserializer (callable) – function to convert strings returned from
memcached to arbitrary objects, must be compatible with
serializer
. An example isdecompress_and_load()
.
Returns:
Classes¶
-
class
baseplate.context.memcache.
MemcacheContextFactory
(pooled_client)¶ Memcache client context factory.
This factory will attach a
MonitoredMemcacheConnection
to an attribute on the context object. When memcache commands are executed via this connection object, they will use connections from the providedPooledClient
and automatically record diagnostic information.Parameters: pooled_client (pymemcache.client.base.PooledClient) – A pooled client. Returns: MonitoredMemcacheConnection
-
class
baseplate.context.memcache.
MonitoredMemcacheConnection
(context_name, server_span, pooled_client)¶ Memcache connection that collects diagnostic information.
This connection acts like a
PooledClient
except that operations are wrapped with diagnostic collection. Some methods may not yet be wrapped with monitoring. Please request assistance if any needed methods are not being monitored.
Serialization/deserialization helpers¶
-
baseplate.context.memcache.lib.
decompress_and_load
(key, serialized, flags)¶ Deserialize data.
This should be paired with
make_dump_and_compress_fn()
.Parameters: Returns: The deserialized value.
-
baseplate.context.memcache.lib.
make_dump_and_compress_fn
(min_compress_length=0, compress_level=1)¶ Make a serializer.
This should be paired with
decompress_and_load()
.The resulting method is a chain of
json.loads()
andzlib
compression. Values that are not JSON serializable will result in aTypeError
.Parameters: Returns: The serializer.
-
baseplate.context.memcache.lib.
decompress_and_unpickle
(key, serialized, flags)¶ Deserialize data stored by
pylibmc
.Warning
This should only be used when sharing caches with applications using
pylibmc
(like r2). New applications should use the safer and future proofeddecompress_and_load()
.Parameters: Returns str value: the deserialized value.
-
baseplate.context.memcache.lib.
make_pickle_and_compress_fn
(min_compress_length=0, compress_level=1)¶ Make a serializer compatible with
pylibmc
readers.The resulting method is a chain of
pickle.dumps()
andzlib
compression. This should be paired withdecompress_and_unpickle()
.Warning
This should only be used when sharing caches with applications using
pylibmc
(like r2). New applications should use the safer and future proofedmake_dump_and_compress_fn()
.Parameters: Returns func memcache_serializer: the serializer method.