Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Laravel Cache: invalid data

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(){
            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(){
            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

like image 914
molerat Avatar asked Mar 17 '23 08:03


1 Answers

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.

like image 63
Margus Pala Avatar answered Mar 24 '23 19:03

Margus Pala