PHP code example of infusionweb / laravel-remote-content-cache

1. Go to this page and download the library: Download infusionweb/laravel-remote-content-cache library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

infusionweb / laravel-remote-content-cache example snippets


'providers' => [
    //
    Kozz\Laravel\Providers\Guzzle::class,
    InfusionWeb\Laravel\ContentCache\ContentCacheServiceProvider::class,
];

'aliases' => [
    //
    'Guzzle' => Kozz\Laravel\Facades\Guzzle::class,
    'ContentCache' => InfusionWeb\Laravel\ContentCache\ContentCacheFacade::class,
];

protected $commands = [
    //
    \InfusionWeb\Laravel\ContentCache\ContentCacheCommand::class,
];



return [

    /*
     * Default configuration.
     */
    'default' => [
        // Default length of time (in minutes) to cache content.
        'minutes' => 60,
    ],

     /*
      * Configuration for custom content filters.
      */
    'podcasts' => [

        // Length of time (in minutes) to cache content.
        'minutes' => 60 * 3, // 3 hours

        // REST API endpoint for service from which to retrieve content.
        'endpoint' => 'https://podcasts.example.com/api/v1/content/podcasts',
        'query' => ['_format' => 'json'],

        // Perform data filter (value) on given field name (key). So in this
        // case, "id" and "episode" will be cast as integers, and "date_created"
        // and "date_changed" will be cast as Carbon date objects. All other
        // values will be cast as strings.
        'filters' => [
            'id' => 'int',
            'date_created' => 'date',
            'date_changed' => 'date',
            'episode' => 'int',
        ],

        // New fields to be created on cached content object from given field names.
        // E.g. Given an "episode" value of 13 and a "title" of "Lucky 13", the
        // new "slug" attribute (useful for use in routes) will have a value of
        // "13-lucky-13".
        'fields' => [
            'slug' => ['episode', 'title'],
        ],

        // Keys by which the cache should be indexed. I.e. each content
        // object will be cached under each of these index keys.
        'keys' => [
            'id',
            'slug',
            'uuid',
            'episode',
        ],
    ],
];



use ContentCache;

// Manually cache remote podcast episodes, if this process is not handled via the
// Artisan console command.
ContentCache::profile('podcasts')->cache();

// Then retrieve a list of all episodes.
$episodes = ContentCache::profile('podcasts')->getAll();

// This could also be shortened to:
$episodes = ContentCache::profile('podcasts')->cache()->getAll();

// Individual content objects can be retrieved via configured indexes.
// In this case, by ID.
$episode = ContentCache::profile('podcasts')->getBy('id', 13);

// Or by slug (from a Laravel Request object), using the "magic function".
$cache = ContentCache::profile('podcasts');
$episode = $cache->getBySlug('13-lucky-13');

// This makes it easy to hand off to a Blade template.
return view('pages.podcast.episode', compact('episode'));
bash
$ php artisan vendor:publish --provider="InfusionWeb\Laravel\ContentCache\ContentCacheServiceProvider"
bash
$ php artisan content:cache
bash
$ php artisan content:cache podcasts