Caching

Cache layer

The cache layer is used to cache your repository data from Prismic. The cache layer is disabled by default and can be enabled through the configuration file. You can also specify the time to live and a prefix for the cache keys.

The cache class makes use of Laravels caching facade. The configuration of the cache itself is done through your default cache config file.

Disable caching for specific models

Prismic eloquent allows you to disable caching per model by overwriting the cacheEnabled property.

class Page extends Model
{
    public $cacheEnabled = false;
}

Now the cache is disabled for this model.

Flush cache on content change

You can easily flush the prismic eloquent cache on your webhook controller to avoid not seeing content changes.

use RobinDrost\PrismicEloquent\Facades\Cache;

class MyWebhookController extends Controller
{
    public function __invoke($payload)
    {
        Cache::clear();
    }
}

Prismic eloquent does not come with a pre-installed webhook controller. Please see the webhook documentation of Prismic for more information on this topic.

Overwriting the cache layer

You are able to overwrite the cache layer by binding a class in your AppServiceProvider.

$this->app->bind('prismiceloquent.cache', YourCache::class);

Make sure your cache class implements the CacheInterface from Prismic. Please see the default cache class of Prismic eloquent.

Last updated