Compression and serialisation

Pyappcache offers pluggable compression and serialisation so you can choose what is used to compress your cache values and how they are serialised. The defaults are gzip and pickle.

Compression

class pyappcache.compression.Compressor(*args, **kwds)

The protocol for compressors to follow

is_compressed(data)

Takes some, possibly compressed data as an argument and returns True if is has been compressed with this compressor, False otherwise.

Return type:

bool

compress(data)

Compress the given bytes with this compressor

Return type:

IO[bytes]

decompress(data)

Decompress the given bytes with this compressor

Return type:

IO[bytes]

class pyappcache.compression.GZIPCompressor(level=5)

A default compressor that is gzip at level 5.

level

Gzip compression level

Serialisation

class pyappcache.serialisation.Serialiser(*args, **kwds)

The protocol for serialisers to follow

class pyappcache.serialisation.PickleSerialiser

A wrapper for pickling.

The difference between this and pickle.load/pickle.dump is that PickleSerialiser returns None when it can’t unpickle - to defend against unreadable cache values.

pickle_protocol = 4

The pickle protocol level (default 4). Changing this default value will be considered a breaking API change.