[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