Home / Snippets / How to enable cache for s3 Filesystem Driver (Disk Caching)
How to enable cache for s3 Filesystem Driver (Disk Caching) cover

How to enable cache for s3 Filesystem Driver (Disk Caching)

546

2 years ago

0 comments

In Laravel, you can enable s3 or other filesystem driver cache and by doing so you will be able to increase the performance of your website. The first step for this is to install the cache adapter using composer.

Install Laravel CachedAdapter


Do run the command below from your terminal.
composer require league/flysystem-cached-adapter "~1.0"

Enable the Cache Driver


And now to enable the cache driver you can specify the 'cache' key and specify the cache details. From the example docs it's using the "Memcached" store and it's set to 600 seconds to expire and has a prefix of "cache-prefix"
's3' => [
    'driver' => 's3',

    // Other Disk Options...

    'cache' => [
        'store' => 'memcached',
        'expire' => 600, // 10 mins
        'prefix' => 'cache-prefix',
    ],
],
But if you are using "redis" and you want it to cache for 1 hour then you can specify it like below.
's3' => [
    'driver' => 's3',
    'key' => env('AWS_ACCESS_KEY_ID'),
    'secret' => env('AWS_SECRET_ACCESS_KEY'),
    'region' => env('AWS_DEFAULT_REGION'),
    'bucket' => env('AWS_BUCKET'),
    'url' => env('AWS_URL'),
    'endpoint' => env('AWS_ENDPOINT'),
    'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),

    'cache' => [
        'store' => 'redis',
        'expire' => 3600, // 1 hour
        'prefix' => 's3-cache',
    ],
],
And now you will get a slight performance boost when accessing items from the disk.

Other Reads

notion avatar

Alaz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

If you like our tutorial, support us by being our Patreon or buy us some coffee ☕️

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this