DEV Community

Cover image for How to Create Own Cache driver and Learn Cache drivers from Laravel
Rohit Urane
Rohit Urane

Posted on

How to Create Own Cache driver and Learn Cache drivers from Laravel

Laravel provides an expressive, unified API for various caching backends. We stored all Cache information in the config/cache.php file of your project. They configure Laravel to use a file cache driver to keep the serialized cached objects in the filesystem.

Driver Prerequisites:-

Database:

You are going with a database cache driver. You will need to create a table that contains cache items.

Schema::create('cache', function ($table) {
    $table->string('key')->unique();
    $table->text('value');
    $table->integer('expiration');
});
Enter fullscreen mode Exit fullscreen mode

Run the artisan command php artisan cache:table. It will generate a migration with the proper schema.

Memcached:

For Memcached driver requires Memcached PECL package. You may list all the Memcached servers in the config/cache.php file.

'memcached' => [
    [
        'host' => '127.0.0.1',
        'port' => 11211,
        'weight' => 100
    ],
],
Enter fullscreen mode Exit fullscreen mode

Read More

Top comments (0)