laravel config cache

作者: 3275508ab630 | 来源:发表于2017-12-13 07:51 被阅读63次

    cache.php

    default 注释翻译:

        /*
        |--------------------------------------------------------------------------
        | Default Cache Store
        |--------------------------------------------------------------------------
        |
        | This option controls the default cache connection that gets used while
        | using this caching library. This connection is used when another is
        | not explicitly specified when executing a given caching function.
        |
        | Supported: "apc", "array", "database", "file", "memcached", "redis"
        |
        */
    
        'default' => env('CACHE_DRIVER', 'file'),
    
        /*
        |--------------------------------------------------------------------------
        | 默认缓存存储
        |--------------------------------------------------------------------------
        | 
        | 此选项控制使用此缓存库时使用的默认缓存连接。
        | 当执行缓存功能时,没有明确指定哪一个时,使用此连接。
        | 
        |
        | 支持:“apc”,“array”,“database”,“file”,“memcached”,“redis”
        |
        */
    
        'default' => env('CACHE_DRIVER', 'file'),
    

    个人理解:缓存的默认存储方式。

    stores 注释翻译:

        /*
        |--------------------------------------------------------------------------
        | 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' => [...],
    
        /*
        |--------------------------------------------------------------------------
        | 缓存存储
        |--------------------------------------------------------------------------
        | 
        | 在这里,您可以定义应用程序的所有缓存“存储”以及其驱动程序。
        | 您甚至可以为同一个缓存驱动程序定义多个存储区,以对存储在缓存中的项目类型进行分组。
        | 
        |
        */
    
        'stores' => [...],
    

    个人理解:笔者推荐下面的文章,来自 MakingChoice 简书
    作者:MakingChoice 链接:http://www.jianshu.com/p/c9c01fcd3ccf 來源:简书

    • apc 全名 Alternative PHP Cache (APC), 是一个开放自由的 PHP opcode 缓存。基于内存的缓存系统。
    • array 缓存在php生命周期里的一个数组里,请求结束了,缓存就没有了,所以线上环境不要用它。
    • file 是使用文件做缓存,默认存储在 storage/framework/cache/data。适合本地开发使用。
    • memcached 文档原文:注意:file,database 缓存驱动不支持『缓存标签』(tags),此外,当使用多标签的缓存被设置为永久存储时,使用 memcached 驱动的缓存有着最佳性能表现,因为 memcached 会自动清除陈旧记录。
    • redis 由于配置默认是和 session 存在同一个数据库里, 推荐把连接换一下,把 connection => 'default' 换成 connection => 'cache'。 然后在 configdatabase.phpredis 数组里增加以下内容。
    'cache' => [
           'host' => env('REDIS_HOST', '127.0.0.1'),
           'password' => env('REDIS_PASSWORD', null),
           'port' => env('REDIS_PORT', 6379),
           'database' => 1,
    ],
    

    prefix 注释翻译:

         /*
        |--------------------------------------------------------------------------
        | 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' => env(
            'CACHE_PREFIX',
            str_slug(env('APP_NAME', 'laravel'), '_').'_cache'
        ),
    
        /*
        |--------------------------------------------------------------------------
        | 缓存键前缀
        |--------------------------------------------------------------------------
        |
        | 当使用基于RAM(内存)的存储(如APC或Memcached)时,可能会有其他应用程序使用相同的缓存。 
        | 所以,我们将指定一个值作为我们所有键的前缀,这样我们可以避免冲突。
        | 
        |
        */
    
        'prefix' => env(
            'CACHE_PREFIX',
            str_slug(env('APP_NAME', 'laravel'), '_').'_cache'
        ),
    

    个人理解:设置键前缀,防止冲突。

    相关文章

      网友评论

        本文标题:laravel config cache

        本文链接:https://www.haomeiwen.com/subject/dhooixtx.html