Caching with Laravel

A tagged laravel cacher is used by default. The cache key and duration can be set inconfig/prismic.php. All endpoints are cached by default.

Cache Rules

Cache rules can be used to override the cache for certain endpoints. You can register your own cache rules in the config file.

Example

The following example won't cache any URLs the are querying for a custom type called product. .

<?php

namespace Incraigulous\PrismicToolkit\CacheRules;


use Incraigulous\PrismicToolkit\Endpoint;
use Incraigulous\PrismicToolkit\CacheRules\Contracts\CacheRule;

class IgnoreProductSearch implements CacheRule
{
    private $endpoint;

    public function __construct(Endpoint $endpoint)
    {
        $this->endpoint = $endpoint;
    }

    public function shouldCache()
    {
        return ! str_contains($this->endpoint->url(), 'at(document.type,"product")');
    }

    public function shouldPrecache()
    {
        return ! str_contains($this->endpoint->url(), 'at(document.type,"product")');
    }
}

Precache

After migrating the database, you should have a table called prismic_endpoints. This keeps a record of all endpoints called by the API. This allows you to precache any endpoint called by your application so you never have to call Prismic as a result of user interaction. You can precache your endpoints with the following command.

php artisan prismic:sync

results matching ""

    No results matching ""