Block cache and URL parameters?
I have a problem with block-caching and can't find a solution:
On my pages a have a special navigation block. In this block caching is enabled. The output of this block depends on a parameter in the URL. But it seems, that the caching algorithm ignores the url paramters and so my block has always the same output. I just can't find a way how to solve that.
So my navigation block should have different output when i visit the pages
Can anybody tell me how to do that?
Thanks a lot
protected $btCacheBlockRecord = false; protected $btCacheBlockOutput = false; protected $btCacheBlockOutputOnPost = false; protected $btCacheBlockOutputForRegisteredUsers = false;
(Or, if you already have code similar to that in your block controller, change the values from "true" to "false" where applicable).
If I understand right, C5 does not care about URL parameters when caching blocks? Sounds a little bit strange for me. Why not introduce a class variable where you can store additional values for the cache key?
So it seems that I have to do it myself with the Cache class. Not really elegant but it should work... :-)
So... I think you'll need to implement your own form of caching. Will require a bit of work but nothing too complicated -- just save your calculated data to a table or file somewhere with a timestamp, and have the block controller code check for how long ago the saved timestamp is and decide if you want to re-calculate or not based on that. (That's of course just a very general approach -- but there's probably some details specific to your situation that will effect how you implement the caching).
Now i just use Cache::set and Cache::get to store my values. Works fine, the only disadvantage is, that the script does not know when content has changed and so the cache should be invalidated...
If I could have a wish to the C5 team, it would be an additional parameter for the BlockController like
protected $btCacheBlockCacheKey = array("param1","param2");
So that these URL parameters are added to the cache key...
This code is off of the top of my head, it is meant for demonstration only
So you would do something like:
ob_start(); //at the top of your block view
//other stuff with your template
//grab your $getVar1 and $getVar2 from $_GET or $_REQUEST
$view = ob_get_flush();
$view = Cache::get('CustomHandle',$getVar1.':'.$getVar2.':'.$bID);
//do that complex stuff and set it to cache as above;
I typed all of this off of the top of my head. Please read up here on the different functions you could use:
That is the general idea to do this sort of thing.
I switched on the APC cache and page caching and this works quite well now. Hopefully I can launch my website in a week.. :-)
Could this be in the way that we are pulling images into the block view?
Within the view we are using the image helper and getThumbnail() functions in case we want to set a height and width as well as cropping. We have found that this generates an image that is around double the image size of the uploaded image, and the quality setting does not have much impact.
$image = $ih->getThumbnail($f, $imageWidth, $imageHeight, array('crop' => true, 'quality'=>10));