<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
silverstripe-terraformers / keys-for-cache example snippets
public function getCacheKey(): string
{
$parts = [
// Parts related to the block itself
static::class,
$this->ID,
$this->LastEdited,
// Parts related to the Items within the block
$this->Items()->max('LastEdited'),
$this->Items()->count(),
// Parts related to the Images assigned to our Items
Image::get()->filter('ID', $this->Items()->column('ImageID'))->max('LastEdited'),
Image::get()->filter('ID', $this->Items()->column('ImageID'))->count(),
];
return implode('-', $parts);
}
class CarouselBlock extends BaseElement
{
private static array $has_many = [
'Items' => CarouselItem::class,
];
// $owns is optional, but quite common in this use case. I've added it here simply to illustrate how $cares
// follows the same paradigm
private static array $owns = [
'Items',
];
private static array $cares = [
'Items',
];
}
class CarouselItem extends DataObject
{
private static array $has_one = [
'Image' => Image::class,
];
// $owns is optional, but quite common in this use case. I've added it here simply to illustrate how $cares
// follows the same paradigm
private static array $owns = [
'Image',
];
private static array $cares = [
'Image',
];
}