Skip to content

Commit

Permalink
Add several methods to support writeable local cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Carlino committed Oct 2, 2018
1 parent 3727e15 commit 27d6b12
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Models/BaseElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,17 @@ public function getController()
return $this->controller;
}

/**
* @param string $name
* @return $this
*/
public function setAreaRelationNameCache(string $name)
{
$this->cacheData['area_relation_name'] = $name;

return $this;
}

/**
* @return Controller
*/
Expand Down
36 changes: 36 additions & 0 deletions src/Models/ElementalArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use SilverStripe\Core\Extensible;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\FieldType\DBHTMLText;
Expand Down Expand Up @@ -87,6 +88,41 @@ public function forTemplate()
return $this->renderWith(static::class);
}

/**
* @param ArrayList $elements
* @return $this
*/
public function setElementsCached(ArrayList $elements)
{
$this->cacheData['elements'] = $elements;

return $this;
}

/**
* @param DataObject $page
* @return $this
*/
public function setOwnerPageCached(DataObject $page)
{
$this->cacheData['owner_page'] = $page;

return $this;
}

/**
* A cache-aware accessor for the elements
* @return ArrayList|DataList
*/
public function Elements()
{
if (isset($this->cacheData['elements'])) {
return $this->cacheData['elements'];
}

return parent::Elements();
}

/**
* Necessary to display results in CMS site search.
*
Expand Down

0 comments on commit 27d6b12

Please # to comment.