cache a single page with parameter
Permalink
I have created a single page that displays information pulled from an external database (not the c5 db). Currently if I go to /event/278 (which mod_rewrite changes to /event/?id=278) everything works fine, but it takes a while for the page to load, presumably because it needs to pull data from the external database.
I turned on full-page caching and I'm not currently using any third-party caching options (APC, Miser, eAccelerator). I was expecting to find in the files/cache/pages a series of folder/files that looked something like e/v/e/278.cache, but instead I've got e/v/e/. I was hoping the the mod_rewrite would trick c5 into creating a full page cache with the external information, but no luck.
Does anyone know if it's possible to create a cached copy of a single page with a parameter? Is it possible with one of the third-party caching options?
Am I missing something, or overthinking this?
Thanks
I turned on full-page caching and I'm not currently using any third-party caching options (APC, Miser, eAccelerator). I was expecting to find in the files/cache/pages a series of folder/files that looked something like e/v/e/278.cache, but instead I've got e/v/e/. I was hoping the the mod_rewrite would trick c5 into creating a full page cache with the external information, but no luck.
Does anyone know if it's possible to create a cached copy of a single page with a parameter? Is it possible with one of the third-party caching options?
Am I missing something, or overthinking this?
Thanks
The best I've been able to do is create a controller method that creates a Cache object like so:
It works, but I haven't found an easily clear a single cache object. I've created a dashboard page that takes an id and then does something like this:
But I agree that it would be awesome to cache single pages with parameters.
public function get_stuff(){ $id = $this->get('id'); $stuff = Cache::get('page_stuff', $id); if(is_obj($stuff)){ return $stuff } $stuff['thing_one'] = $model->get_thing_one($id); $stuff['thing_two'] = $model->get_thing_two($id); //repeat as needed Cache::set('page_stuff', $id, $stuff); return $stuff; }
It works, but I haven't found an easily clear a single cache object. I've created a dashboard page that takes an id and then does something like this:
public function clear_object($id){ Cache::delete('page_stuff', $id); }
But I agree that it would be awesome to cache single pages with parameters.
Single pages don't support full page caching. This is because they have an attribute called 'isGeneratedCollection' checked.
I think you can easily solve this issue by overriding /core/libraries/page_cache/library.php
The code below is untested, but I'm sure it's a good direction.
You need to create a checkbox attribute called 'enable_single_page_cache' and attach it to a single page.
Let me know if it works :)
Adri
I think you can easily solve this issue by overriding /core/libraries/page_cache/library.php
The code below is untested, but I'm sure it's a good direction.
<?php defined('C5_EXECUTE') or die("Access Denied."); abstract class PageCache extends Concrete5_Library_PageCache { public function shouldAddToCache(View $v) { $c = $v->getCollectionObject(); if (!is_object($c)) { return false; } $cp = new Permissions($c); if (!$cp->canViewPage()) { return false; } $u = new User(); $allowedControllerActions = array('view'); if (is_object($v->controller)) {
Viewing 15 lines of 50 lines. View entire code block.
You need to create a checkbox attribute called 'enable_single_page_cache' and attach it to a single page.
Let me know if it works :)
Adri
It doesn't work.
It works as Single Pages normally does. Without any parameters page uses Full Page Cache, but with parameters it does always overwrite previous cache file every time.
After that Single Page without parameters displays cached usually wrong cached content (usually with those ones when Single Page was used with parameters).
It works as Single Pages normally does. Without any parameters page uses Full Page Cache, but with parameters it does always overwrite previous cache file every time.
After that Single Page without parameters displays cached usually wrong cached content (usually with those ones when Single Page was used with parameters).
Ok, my version (in attachment).
Not tested much, but it works.
It creates cache files based on Request instead of Page. So basicly You could flood cache-directory with several cachefiles just changing parametes, and leave Zend to take care of the cleanup.
...but they're now cached.
edit:
Cache files are actually (in the attached overrides) named with md5 to prevent invalid filenames (dont know if it is even possible).
Not tested much, but it works.
It creates cache files based on Request instead of Page. So basicly You could flood cache-directory with several cachefiles just changing parametes, and leave Zend to take care of the cleanup.
...but they're now cached.
edit:
Cache files are actually (in the attached overrides) named with md5 to prevent invalid filenames (dont know if it is even possible).
I'm using heavily Single Pages on couple of sites, where I only change parameters to change the page content.
It would be more than great, if Full Page Caching would work on Single Pages with Parameters.