skip to Main Content

The cache prefix setting has the default value:

'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache')

But when I cache some data (using Redis), the cache key has an unexpected format:

app_database_app_cache:some-data

The cache key is prefixed with the database prefix. I expected the cache key to just be:

app_cache:some-data

Is this the correct behavior, and is it possible to change it somewhere?

2

Answers


  1. Chosen as BEST ANSWER

    I somehow didn't notice the REDIS_PREFIX env var which prepends a prefix. The file caching of config.php also made it harder to debug.


  2. For those who still lost, Redis key is the combination of two variables in Laravel.

    1. REDIS_PREFIX – config/database.php
    'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
    
    1. CACHE_PREFIX – config/cache.php
    'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache'),
    

    If you see an unexpected prefix or suffix in your key, you’d better look at those two.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search