Wallogit.com
2017 © Pedro Peláez
A composer package for caching for all quintype PHP projects. All publisher websites should be cached to reduce load to the server., (*1)
$ composer update
"require": {
...
...
"quintype/caching":"1.0.0"
},
$ composer install or $ composer update
'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,
],
];
}
The argument is an associative array with following keys:, (*2)
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])));