LCD344
July 28, 2018, 1:31pm
1
Hi!
I have a site that includes pages that are protected by password. the problem is that the cache renders those templates after someone logs into them (As they are cached it seems to skip the controller and everything).
I know I can disable cache by url, but the way the site is built allows those pages to have different urls and locations. so the question is, can cache bbe disabled for specific templates?
Thanks!
If you filter your site inex by template, you should get a collection of pages, from which you can create an array of uris to exclude from the cache.
LCD344
July 28, 2018, 5:56pm
3
I was trying to do that, but accessing the site() in the config is impossible as I am using multi lang kirby - and I am hitting this:
With kirby v2.5.6 this works:
site/config/config.php
dump(kirby());
But this:
<?php
c::set('languages', array(
array(
'code' => 'en',
'name' => 'English',
'default' => true,
'locale' => 'en_US',
'url'...
bug
Is there a workaround?
LCD344:
Is there a workaround?
I don’t know any.
But does the list of excluded URLs have to be dynamic?
LCD344
July 28, 2018, 7:41pm
5
If nothing changes we will force it not to be. But its preferable if it was dynamic
ps. Thanks for the help!
Have you tried setting the excluded URL’s dynamically via a URL in a plugin ?
e.g. this:
function excludedfromcache() {
$excludedPages = kirby()->site()->index()->filterBy('template', 'page');
$exclArr = [];
foreach($excludedPages as $p) {
array_push($exclArr, $p->uri());
}
return $exclArr;
}
c::set('cache.ignore', excludedfromcache());
Edit: Nevermind. It suppresses the errors, but in my quick test, pages which should be excluded get cached anyway. I can only assume setting cache.ignore
in a plugin is too late.
LCD344
July 28, 2018, 7:47pm
7
yea, I’ve tried different things, plugins, controllers… I think it has to be before the cache true for it to work
Another thing I just. tested is to write the URIs to file and then to. read this file.
c::set('cache', true);
$excluded = json_decode(f::read(kirby()->roots()->index().'/urls.txt'));
c::set('cache.ignore', $excluded);
Looks like it could work.
This list could then be updated via hooks.
Clever & out-of-the-box.
Be sure to have logic to invalidate and rebuild this cache when needed though.
LCD344
July 29, 2018, 2:52pm
10
interesting ideas - I will check this out.