Serialization¶
By default, the library uses native PHP serialization (serialize/unserialize) to store data. However, you can switch to other serializers for better performance, security, or interoperability.
Available Serializers¶
The library includes several built-in serializers in Fyennyi\AsyncCache\Serializer:
PhpSerializer(Default): Uses standard PHP serialization. Best compatibility.JsonSerializer: Stores data as JSON. Good for debugging and cross-language compatibility.- Note: Does not support objects unless they implement
JsonSerializable.
- Note: Does not support objects unless they implement
IgbinarySerializer: Uses theigbinaryextension (if available). Significantly smaller and faster than standard PHP serialization.EncryptingSerializer: Wraps another serializer and encrypts the output using OpenSSL (AES-256-CBC).
Configuring Serialization¶
Use withSerializer on the builder.
Using JSON¶
use Fyennyi\AsyncCache\Serializer\JsonSerializer;
$manager = AsyncCacheBuilder::create($adapter)
->withSerializer(new JsonSerializer())
->build();
Using Encryption¶
use Fyennyi\AsyncCache\Serializer\EncryptingSerializer;
use Fyennyi\AsyncCache\Serializer\PhpSerializer;
$key = 'super-secret-key-must-be-32-bytes'; // 32 chars for AES-256
$serializer = new EncryptingSerializer(
new PhpSerializer(),
$key
);
$manager = AsyncCacheBuilder::create($adapter)
->withSerializer($serializer)
->build();
Compression¶
Independent of the serializer, you can enable GZIP compression for large items via CacheOptions.