Cache Flashcards
What are the cache drivers supported by Laravel?
Memcached, Redis & file
What the default cache driver used by Laravel?
The file cache driver
Which of the three supported cache drivers are recommended for larger apps?
Memcached or Redis
In order to use the file/database cache driver what is required to be setup?
When using the database cache driver, you will need to setup a table to contain the cache items. You’ll find an example Schema declaration for the table below:
Schema::create('cache', function ($table) { $table->string('key')->unique(); $table->text('value'); $table->integer('expiration'); });
Which Artisan Command will generate a migration with the proper schema for the database cache driver?
php artisan cache:table
For Memcached what is the name of the required package?
Memcached PECL package
In which file can you list all of your Memcached servers?
You may list all of your Memcached servers in the config/cache.php configuration file:
'memcached' => [ [ 'host' => '127.0.0.1', 'port' => 11211, 'weight' => 100 ], ],
Which option in the config/cache.php file can also be set to to a UNIX socket path?
You may also set the host option to a 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 ], ],
Before using a Redis cache with Laravel, you will need to either install?
the predis/predis package (~1.0) via Composer or install the PhpRedis PHP extension via PECL
What contracts provide access to Laravel’s cache services?
Illuminate\Contracts\Cache\Factory and Illuminate\Contracts\Cache\Repository
What is the purpose of the factory contract?
The Factory contract provides access to all cache drivers defined for your application.
What is the purpose of the repository contract?
The Repository contract is typically an implementation of the default cache driver for your application as specified by your cache configuration file.
What is the purpose of the Cache Facade?
The Cache facade provides convenient, terse access to the underlying implementations of the Laravel cache contracts:
How are you able to access multiple cache stores?
Using the Cache facade, you may access various cache stores via the store method. The key passed to the store method should correspond to one of the stores listed in the stores configuration array in your cache configuration file:
$value = Cache::store(‘file’)->get(‘foo’);
Cache::store(‘redis’)->put(‘bar’, ‘baz’, 10);
What is the purpose of the get method?
The get method on the Cache facade is used to retrieve items from the cache. If the item does not exist in the cache, null will be returned. If you wish, you may pass a second argument to the get method specifying the default value you wish to be returned if the item doesn’t exist:
$value = Cache::get(‘key’);
$value = Cache::get(‘key’, ‘default’);