I have two functions that look pretty much the same and are called right one after another as AJAX-requests from a JavaScript function.
/**
* get all Airports for autocomplete
*/
public function getAirports(){
if(Cache::has('airports')){
return Cache::get('airports');
}
$airportModel = new Airport;
$airports = json_encode($airportModel -> _getForAutocomplete('iata_faa_code'));
Cache::put('airports', $airports, 600);
return $airports;
}
/**
* get all Countries for autocomplete
*/
public function getCountries(){
if(Cache::has('countries')){
return Cache::get('countries');
}
$countryModel = new Country;
$countries = json_encode($countryModel -> _getForAutocomplete('two_letter_code'));
Cache::put('countries', $countries, 600);
return $countries;
}
Now when I go to the page for the first time, I get the data correctly (since it has not been cached yet). If I go to the page for the second time, I get the countries but for the airports I get following error and cannot see why.
{"error":{"type":"Illuminate\\Encryption\\DecryptException","message":"Invalid data.","file":"C:\\xampp\\htdocs\\laravel\\vendor\\laravel\\framework\\src\\Illuminate\\Encryption\\Encrypter.php","line":132}}
I have found out, that it has to do something with Cache by Googling and removing the Cache-part. I would be very glad if somebody could help me out with that one.
By the way, I am using the database as my cache driver.
Best regards, Marcel
I believe there is something fishy going of with serialization. it can be possible that the $airports gets corrupted during serialization.
If the airports string value is too long for MySQL field then end will be silently truncated and decryption of data fails.
By default Laravel recommends the value field type to be text. To make it bigger you can use mediumText or longText fields.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With