imannms / laravel-s3-cache-driver
Laravel S3 cache driver. Support: Amazon S3, Digital Ocean Spaces, etc.
Installs: 36 157
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 3
Open Issues: 0
Requires
- php: >=5.6
- laravel/framework: >=5.2
- league/flysystem-aws-s3-v3: ^1.0
Requires (Dev)
- phpunit/phpunit: ^6.1|^7.5
This package is auto-updated.
Last update: 2024-12-18 18:03:48 UTC
README
S3 cache driver for Laravel 5 and 6. Support: Amazon S3, Digital Ocean Spaces, etc.
The repository is originally forked from Illuminate\Cache\FileStore
.
The advantages of using S3:
- S3 have an unlimited storage or big storage.
- You can cache everything without worried about running out of storage capacity.
- It's cheap!
Note: Redis, Memcached, and almost others laravel default cache store have a limited storage.
How to install
Install using composer
composer require imannms/laravel-s3-cache-driver
For Laravel 5.5+
Nothing is needed, package auto-discovery will work.
For Laravel 5.2+
Add to config/app.php
.
/* * Package Service Providers... */ Imannms\LaravelS3CacheDriver\S3CacheServiceProvider::class,
Add config
Add to config/cache.php
with the config template bellow.
Please choose one.
Amazon S3 config template.
'stores' => [ // other stores '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'), 'path' => env('AWS_PATH', 'cache'), // cache root directory, you can change it to suit your need ], ]
Digital Ocean Spaces config template.
'stores' => [ // other stores 'do_spaces' => [ 'driver' => 's3', 'key' => env('DO_SPACES_KEY'), 'secret' => env('DO_SPACES_SECRET'), 'region' => env('DO_SPACES_REGION'), 'bucket' => env('DO_SPACES_BUCKET'), 'endpoint' => env('DO_SPACES_ENDPOINT'), 'path' => env('DO_SPACES_PATH', 'cache'), // cache root directory, you can change it to suit your need ], ]
Finally
Run php artisan config:cache
.
How to use
use Cache; Cache::store('s3')->put('key', 'value', 60*5); Cache::store('s3')->get('key');
Recommendation
Enable CDN on your cloud storage for faster speed.