Framework: [5.0][5.1] 从 4.2 升级后的缓存问题

创建于 2016-01-05  ·  3评论  ·  资料来源: laravel/framework

你好 !
一年多以来,我有一个运行 laravel 4.2 的项目。
本周我开始升级过程以使用 5.0,然后是 5.1,最终我的目标是 5.2。

5.0 升级很顺利,除了这个缓存问题,一切都运行良好。
首先我想“让我们升级到 5.1 看看它是否有效”,但它没有。

我使用生成缓存并获得此异常的工匠命令:

Refreshing the message cache...

  [InvalidArgumentException]
  Cache store [] is not defined.

首先,我认为这是一个安装问题。 我按照 laravel 官方文档指南从头开始重新安装了所有内容。 我仔细检查了每个配置等...但我仍然遇到这个问题。

有可以帮助重现/帮助我的信息:

composer.json内容:

{
    "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_ 配置文件:

<?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',

);

为了演示这个问题,我在主页中尝试了一个简单的缓存用例:

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

这是我在浏览器中获得的调用堆栈(剪切到它在我的文件中传递的位置):

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

有没有人已经遇到过这种错误或知道要尝试什么?
如果您需要询问,我可以提供更具体的细节=)

最有用的评论

好吧,我想我很愚蠢。 如果有人像我一样落入这个“陷阱”,只需发布​​解决方案:

  • 在 Laravel 4.2中,默认缓存驱动程序的配置键是"driver" => "file"例如
  • 在 Laravel 5.x中,这个键被命名为"default" => "file"

迁移时,我逐个检查配置内容以检查新的密钥/配置,但错过了这个细节。 所以我的 5.1 中有"driver" => "file"而不是"default" => "file"

所有3条评论

请在论坛上提问。

好吧,我想我很愚蠢。 如果有人像我一样落入这个“陷阱”,只需发布​​解决方案:

  • 在 Laravel 4.2中,默认缓存驱动程序的配置键是"driver" => "file"例如
  • 在 Laravel 5.x中,这个键被命名为"default" => "file"

迁移时,我逐个检查配置内容以检查新的密钥/配置,但错过了这个细节。 所以我的 5.1 中有"driver" => "file"而不是"default" => "file"

即使在 3 年后,再次检查 .env 文件,以确保提供了正确的参数

此页面是否有帮助?
0 / 5 - 0 等级