I'm in the middle of adding some simple post-code location caching to our system. I've got a "Location" object:
class Location {
public function __construct(
public string $postcode,
public float $latitude,
public float $longitude) {}
}
When I cache this object in redis (hard coded lat/long for testing):
public function getData($postcode) : Location {
$location = Cache::remember("Location1", 60, function() use ($postcode) {
return new Location($postcode, 52.7845352, -2.660324);
});
return $location;
}
I get excessively long floats in Redis, just wasting space:
"latitude";d:52.78453520000000054324118536897003650665283203125;s:9:"longitude";d:-2.66032400000000013307044355315156280994415283203125
Is there a reason for this I'm missing? How do I stop it?
Thanks.