LAPS Posted March 23, 2020 Share Posted March 23, 2020 According to this old post, I'm trying to use the PW cache feature: $my_page = $pages->get($pageId); if($my_page->viewable()) { $content = $cache->get("my_page"); if(!$content) { $content = renderCustom($my_page->children); $cache->save('my_page', $content, 3600); } echo $content; } function renderCustom(PageArray $items) { foreach($items as $item) { echo $item->title; // ... heavy content loading } } After loading the page which renders the above code, in the admin I can see something was cached (note: I'm using ClearCacheAdmin) : But when I reload the page the cached value seems do not be used and the page loads slowly. The result of doing var_dump() is the following: var_dump($cache); // return object(ProcessWire\WireCache)#20 (0) { } $content = $cache->get("my_page"); var_dump($content); // return string(0) "" What could be the problem? Link to comment Share on other sites More sharing options...
teppo Posted March 23, 2020 Share Posted March 23, 2020 function renderCustom(PageArray $items) { foreach($items as $item) { echo $item->title; // ... heavy content loading } } Is this just an example, or is your actual function also just echoing content? If so, that right there could be your problem — echo will output the content right way instead of returning it for assignment. Try something like this instead: function renderCustom(PageArray $items) { $out = ""; foreach($items as $item) { $out .= $item->title; // ... heavy content loading } return $out; } 1 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now