PHP code example of quintype / caching

1. Go to this page and download the library: Download quintype/caching 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/ */

    

quintype / caching example snippets


"        ...
        ...
        "quintype/caching":"1.0.0"
    },

'aliases' => [
        ...
        ...
        'Caching' => Quintype\Caching\Caching::class
    ],

use Caching;

public function __construct(){
  $this->caching = new Caching();
  $this->defaultCacheParams = [
      'publisherId' => <publisher_id>,
      'cdnTTLs' => [
        'max-age' => 3 * 60,
        'stale-while-revalidate' => 5 * 60,
        'stale-if-error' => 4 * 60 * 60,
      ],
      'browserTTLs' => [
        'max-age' => 60,
      ],
  ];
}

return response(view("home_page", $this->toView([])))
        ->withHeaders($this->caching->buildCacheHeaders(array_merge($this->defaultCacheParams, ["locationId" => "home", "storyGroup" => "top", "storiesToCache" => $storiesToCache])));

return response(view("section_page", $this->toView([])))
        ->withHeaders($this->caching->buildCacheHeaders(array_merge($this->defaultCacheParams, ["locationId" => $params["section-id"], "storyGroup" => $params["story-group"], "storiesToCache" => $storiesToCache])));

return response(view("story_page", $this->toView([])))
        ->withHeaders($this->caching->buildCacheHeaders(array_merge($this->defaultCacheParams, ["storiesToCache" => $storiesToCache])));

return response(view("collection_page", $this->toView([])))
        ->withHeaders($this->caching->buildCacheHeaders(array_merge($this->defaultCacheParams, ["locationId" => "<depends_on_the_page>", "storiesFrom"=> "collection", "storiesToCache" => $storiesToCache])));