A serializer is responsible for serializing a response so it can be stored in the cache, and for rebuilding the response from the cache.
The default JsonSerializer will work in most cases. It serializes responses as JSON, including the status code, headers, and content.
##Creating a custom serializer
If you have special serialization needs, you can create a class that implements the Serializer interface.
namespace App\Serializers;
use Spatie\ResponseCache\Serializers\Serializer;
use Symfony\Component\HttpFoundation\Response;
class CustomSerializer implements Serializer
{
public function serialize(Response $response): string
{
}
public function unserialize(string $serializedResponse): Response
{
}
}
Then register your custom serializer in the config file.
'serializer' => \App\Serializers\CustomSerializer::class,