Caching mechanism not working

Issue #47 resolved
Silvio Kühn created an issue

I think the caching that can be enabled by annotation @Api\Cache does not work.

The content attribute of the caching file in typo3temp/var/cache/data/nnhelpers seems to be always empty.

s:35:"{"content":{},"expires":1689342754}";

This is caused by ApiController Line 132 where $json is passed to cache instead of $result. The cache tries so serialize a complete \TYPO3\CMS\Core\Http\Response object which fails.

But even if this will be fixed, caching can still fail, e.g. when you return a repository result like (QueryInterface) in your own API implementation.

Like this:

    /**
     * here should be some documentation
     *
     * @Api\Cache
     * @Api\Access("public")
     * @return array
     */
    public function getExampleAction() {
        // This will not be cached because QueryResultInterface is not serializable.
        return $this->exampleRepository->findAll();

        // This would work with caching.
        // return \nn\t3::Db()->findAll('tx_justy_domain_model_pointofcontact');
    }