Framework: [5.0][5.1] Cache issue after upgrade from 4.2

Created on 5 Jan 2016  ·  3Comments  ·  Source: laravel/framework

Hi !
I have a project running laravel 4.2 since more than a year.
This week I've started the upgrade process to use the 5.0 then 5.1 and ultimately I'm aiming at 5.2.

The 5.0 upgrade went fine, everything worked perfectly except this caching issue.
First I thought "Let's upgrate to 5.1 and see if it works" but it didn't.

I use an artisan command that generates cache and get this exception :

Refreshing the message cache...

  [InvalidArgumentException]
  Cache store [] is not defined.

First I thought it was an installation issue. I re-installed everything from scratch following the laravel official doc guide. i doubled check every configuration etc... But I'm still having this issue.

There is informations that can help reproduce / help me:

composer.json content:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "laravel/framework": "5.1.*",
        "illuminate/html": "5.*",
        "andywer/js-localization": "dev-laravel-5",
        "laracasts/flash" : "~1.0"
    },
    "require-dev": {
        "phpunit/phpunit": "~4.0",
        "phpspec/phpspec": "~2.1"
    },
    "autoload": {
        "classmap": [
            "database",
            "app/Models",
            "app/Http/Controllers"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-install-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-create-project-cmd": [
            "php -r \"copy('.env.example', '.env');\"",
            "php artisan key:generate"
        ]
    },
    "config": {
        "preferred-install": "dist"
    },
    "minimum-stability": "stable"
}

_cache.php_ config file:

<?php

return array(

    /*
    |--------------------------------------------------------------------------
    | Default Cache Driver
    |--------------------------------------------------------------------------
    |
    | This option controls the default cache "driver" that will be used when
    | using the Caching library. Of course, you may use other drivers any
    | time you wish. This is the default when another is not specified.
    |
    | Supported: "file", "database", "apc", "memcached", "redis", "array"
    |
    */

    'driver' => 'file',

    /*
    |--------------------------------------------------------------------------
    | Cache Stores
    |--------------------------------------------------------------------------
    |
    | Here you may define all of the cache "stores" for your application as
    | well as their drivers. You may even define multiple stores for the
    | same cache driver to group types of items stored in your caches.
    |
    */
    'stores' => [
        'apc' => [
            'driver' => 'apc',
        ],
        'array' => [
            'driver' => 'array',
        ],
        'database' => [
            'driver' => 'database',
            'table'  => 'cache',
            'connection' => 'mysql',
        ],
        'file' => [
            'driver' => 'file',
            'path'   => storage_path('framework/cache'),
        ],
        'memcached' => [
            'driver'  => 'memcached',
            'servers' => [
                [
                    'host' => '127.0.0.1', 'port' => 11211, 'weight' => 100,
                ],
            ],
        ],
        'redis' => [
            'driver' => 'redis',
            'connection' => 'default',
        ],
    ],
    /*
    |--------------------------------------------------------------------------
    | Cache Key Prefix
    |--------------------------------------------------------------------------
    |
    | When utilizing a RAM based store such as APC or Memcached, there might
    | be other applications utilizing the same cache. So, we'll specify a
    | value to get prefixed to all our keys so we can avoid collisions.
    |
    */
    'prefix' => 'laravel',

);

To demonstrate the issue, I tried a simple cache use case in my home page:

        public function index()
    {
        Cache::put('toto', 'titi', 1);
        $value = Cache::get('toto');
        return View::make('pages.accueil');
    }

And here is the call stack that I get in the browser (cut where it passes in my file):

Whoops, looks like something went wrong.

1/1
InvalidArgumentException in CacheManager.php line 93:
Cache store [] is not defined.
in CacheManager.php line 93
at CacheManager->resolve(null) in CacheManager.php line 77
at CacheManager->get(null) in CacheManager.php line 55
at CacheManager->store() in CacheManager.php line 318
at CacheManager->__call('put', array('toto', 'titi', '1')) in Facade.php line 222
at CacheManager->put('toto', 'titi', '1') in Facade.php line 222
at Facade::__callStatic('put', array('toto', 'titi', '1')) in AccueilController.php line 13
at Cache::put('toto', 'titi', '1') in AccueilController.php line 13
at AccueilController->index()

Does anyone already faced this kind of bug or have any idea of what to try ?
I can give more specific details if you need just ask =)

Most helpful comment

Okay, I'm quite stupid I guess. Just posting the solution if someone ever fall in this "trap" like I did:

  • In Laravel 4.2, the config key for default cache driver is "driver" => "file" for example
  • In Laravel 5.x, this key is named "default" => "file"

While migrating, I wopied config content, key by key to check for new key / config but miss this detail. so I had "driver" => "file" in my 5.1 instead of "default" => "file"

All 3 comments

Please ask on the forums.

Okay, I'm quite stupid I guess. Just posting the solution if someone ever fall in this "trap" like I did:

  • In Laravel 4.2, the config key for default cache driver is "driver" => "file" for example
  • In Laravel 5.x, this key is named "default" => "file"

While migrating, I wopied config content, key by key to check for new key / config but miss this detail. so I had "driver" => "file" in my 5.1 instead of "default" => "file"

Even after 3 years, Double check the .env file, to ensure correct arguments were provided

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JamborJan picture JamborJan  ·  3Comments

klimentLambevski picture klimentLambevski  ·  3Comments

felixsanz picture felixsanz  ·  3Comments

iivanov2 picture iivanov2  ·  3Comments

PhiloNL picture PhiloNL  ·  3Comments