jeudi 2 février 2023

What's the difference between cache Store and Repository in Laravel?

So I've been doing some reading on the Laravel 9 source code, particularly on the Illuminate\Cache namespace. The 3 types of classes that I noticed are: CacheManager, Repository and Store.

From what I've read, the CacheManager class is an implementation of the abstract factory pattern. When the CacheManager::get() method is called, given the store name, it will resolve an instance of the appropriate Store, and wrap it in a Repository object. Then, it will return the Repository object.

When Repository::get() is called, it will call Store::get() to actually get the value.

My question is, why have one Repository and many Store classes? Why don't CacheManager::get() skip the Repository and just return a Store object?

Or rather, why not have many Repository classes: RedisRepository, DatabaseRepository, ApcRepository, and no Store ? What design pattern is this?

I've tried searching on StackOverflow and Laracasts Forum, but nobody seems to have asked this question yet.

Aucun commentaire:

Enregistrer un commentaire