[TYPO3-mvc] Caching framework inside extbase extension
Kevin Ulrich Moschallski
km at 3digit.de
Thu Dec 30 16:49:22 CET 2010
Hi list,
i'm writing an extbase extension which shows references on a map.
Because i want to display all of them on the focus of germany i have
>300 results from my repository. The references are sorted by groups,
this is currently the only filter option.
To speed things up i implemented the caching framework in my extension.
First i noticed, it seems that i can't store the result of
$this->referenceRepository->toArray() in the cache. I get an exception
when passing the cached array to fluid. I guess this is because many
objects are lazy inside the array.
My next step was to store the result of $this->view->render() instead
and push it with $this->result->setContent().
This works fine, my only problem is, that the "normal" view output is
also rendered, which gives me some translated error messages from my
template that the necessary objects are empty.
For a workaround i pass a "nocache" object to the view to supress the
output with a if condition in the template.
My question now is, if there is a way to supress the fluid view
rendering or another way to cache plain html content inside extbase.
Maybe someone did this before and is willing to help me.
Thanks for help in advance.
Here is the code:
$this->view->assign('demand', $demand);
if
($this->cacheInstance->has(hash('md5','category'.$demand->getCategory())))
{
$content = $this->cacheInstance->get(hash('md5',
'category'.$demand->getCategory()));
$this->response->setContent($content);
}
else {
$references = $this->referenceRepository->findDemanded($demand)->toArray();
$this->view->assign('nocache', 1);
$this->view->assign('categories', $this->categoryRepository->findAll());
$this->view->assign('references', $references);
$this->cacheInstance->set(hash('md5',
'category'.$demand->getCategory()), $this->view->render(), array('type'
=> 'references'));
}
Regards,
Kevin
More information about the TYPO3-project-typo3v4mvc
mailing list