1
Q

Where do you need to implement a contract to create a custom cache driver?

A

Illuminate\Contracts\Cache\Store

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Given a fully set up custom cache driver, how do you call upon it?

A
Cache::extend('NAME FOR THIS CACHE', function (Application $app) {
    return Cache::repository(new NAME OF CACHE DRIVER);
});
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can you register a new cache driver?

A

To register the custom cache driver with Laravel, we will use the extend method on the Cache facade. Since other service providers may attempt to read cached values within their boot method, we will register our custom driver within a booting callback. By using the booting callback, we can ensure that the custom driver is registered just before the boot method is called on our application’s service providers but after the register method is called on all of the service providers. We will register our booting callback within the register method of our application’s App\Providers\AppServiceProvider class:

public function register(): void
{
    $this->app->booting(function () {
         Cache::extend('mongo', function (Application $app) {
             return Cache::repository(new MongoStore);
         });
     });
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which environmental variable do you need to update after registering your extension?

A

CACHE_STORE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the default cache driver used by Laravel called?

A

database

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

If your application does not contain the database migration, how can you create it using Artisan?

A

php artisan make:cache-table
php artisan migrate

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What gets returned, if you attempt to use the Cache facade’s get method for an item, that does not exist in the cache?

A

null

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Define a variable $value using the cached items “key” and “default”!

A

$value = Cache::get('key', 'default');

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

You don’t always want the default values of variables to be retrieved when an item does not exist in cache. How can you pass a closure as the default value?

A
$value = Cache::get('NAME OF ITEM', function () {
    return DB::table(/* ... */)->get();
});
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which method can you use to see if an item exists in cache?

A

Cache::has('NAME OF ITEM')

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What will Cache::has(‘example’) return, if the item exists, but has the value “null”?

A

false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How can you put an item into cache? Specify the amount of time that it should be cached for as 10 minutes!

A

Cache::put('example', 'value', now()->addMinutes(10));

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Retrieve the value “example” as $value from the cache, if it isn’t cached yet retrieve from the database and cache it for $seconds!

A
$value = Cache::remember('example', $seconds, function () {
    return DB::table('example')->get();
});
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How can you Cache a retrieved item for an unlimited amount of time?

A
Cache::rememberForever('example', function() {
    return DB::table('example')->get();
});
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Retrieve “example” as $value from cache and then delete the item!

A

$value = Cache::pull('example');

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you put items into cache indefinitely?

A

Cache::put('example', 'value');

By not specifying an amount of time, it will be cached forever

17
Q

What do you need to do to only add an item into cache, if the item is not cached already?

A

Cache::add('example', 'value', $seconds);

18
Q

What will Cache::add return, if the value was successfully cached?

A

true

19
Q

What will Cache::add return, if the value already existed in cache?

A

false

20
Q

How can you add something to cache forever?

A

Cache::forever('example', 'value');

21
Q

Remove an item from cache!

A

Cache::forget('example');

22
Q

Remove items from cache using the put method!

A

Cache::put('example', 'value', -5);

23
Q

Clear the entire cache!

A

Cache::flush();

Flushing the cache does not respect your configured cache “prefix” and will remove all entries from the cache. Consider this carefully when clearing a cache which is shared by other applications.

24
Q

Store a value in cache using the global cache function!

A

$value = cache('example');

25
Q

Add 2 values to cache for 10 minutes using the global cache function!

A

cache(['example' => 'value'], now()->addMinutes(10));

26
Q

How can you call other caching methods in the global cache function?

A

cache()->
enter the other method after the ->