@sid405 can you show me a sample row from the cache table?
Dealing with DecryptException('Invalid data.');
Hello guys.
I'm in a bit of a situation here so i thought i'd ask for a hand.
Currently working on data intensive an application that will need caching. When i use 'file' or even 'memcached' as storage for the cache, everything is fine and dandy. the problem is i need to use 'database'.
The keys are getting correctly stored into the cache table, and even identified correctly with has(). When i then try to get the value for the key, i get the following error:
Illuminate \ Encryption \ DecryptException
Invalid data.
Open: /Applications/MAMP/htdocs/youandbio.com/vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php
$payload = json_decode(base64_decode($payload), true);
// If the payload is not valid JSON or does not have the proper keys set we will
// assume it is invalid and bail out of the routine since we will not be able
// to decrypt the given value. We'll also check the MAC for this encryption.
if ( ! $payload || $this->invalidPayload($payload))
{
throw new DecryptException('Invalid data.');
}
Here's the code of the class that does the storing and the fetching:
<?php namespace Acme\Cache;
use Illuminate\Cache\CacheManager;
class LaravelCache implements CacheInterface {
protected $cache;
public function __construct(CacheManager $cache)
{
$this->cache = $cache;
}
public function get($key)
{
return $this->cache->get($key);
}
public function put($key, $value)
{
return $this->cache->forever($key, $value);
}
public function has($key)
{
return $this->cache->has($key);
}
}
Then on the various cache decorators are pulled up like this
if($this->cache->has($key))
{
return $this->cache->get($key);
}
Any suggestions would be appreciated, because i can't see to get round this.
Thank you in advance
@sid405 I think I have found out the problem. It seems to me that your 64 enocded data is being strip down due to column length and I think you are storing something relatively big. I just reproduced your error by adding a very large cache value into the database. Make the following changes inside your schema, rollback and rerun the migration:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCacheTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('cache', function(Blueprint $table)
{
$table->string('key')->unique();
$table->longText('value');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('cache');
}
}
The record you pasted previously giving me a NULL and I think it is because it is striped down.
After migrating the cache table. Put the same cache value and read back hopefully you will not get error this time. Finger Crossed!
Usman
Please or to participate in this conversation.