[Laravel5.2 documentation] service-cache

Source: Internet
Author: User
Tags php memcached
[Laravel5.2 documentation] service-cache 1. configuration

Laravel provides unified APIs for different cache systems. The cache configuration is in config/cache. php. In this file, you can specify which cache driver is used by default in the application. Laravel currently supports mainstream cache backends, such as Memcached and Redis.

The cache configuration file also contains other documented options, which are carefully read. By default, Laravel is configured to use file caching, which stores serialized data and cached objects in the file system. For large applications, we recommend that you use memory caches such as Memcached or APC. you can even configure multiple cache configurations for the same driver.

1.1 Cache preparation

Database

When using the database cache driver, you need to set a table to contain cache items. The Schema declaration of the table is as follows:

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

Memcached

The Memcached cache requires that the Memcached PECL package is installed, that is, the PHP Memcached extension.

Memcached: addServer uses the TCP/IP protocol by default:

'memcached' => [    [        'host' => '127.0.0.1',        'port' => 11211,        'weight' => 100    ],],

You can also set the host option to the UNIX socket path. if you do this, the port option should be set to 0:

'memcached' => [    [        'host' => '/var/run/memcached/memcached.sock',        'port' => 0,        'weight' => 100    ],],

Redis

Before using Laravel's Redis Cache, you need to install the predis/predis package through Composer (~ 1.0 ).

Want to know

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.