Jump to content

Extend cache for dynamic pages


derixithy
 Share

Recommended Posts

I'm reusing pages depending on the url of the site and want to cache these pages.

For example example.com/blog/1 and example.nl/blog/1 would use the same template but i'm extending the Page to limit the results depending on url.

Is there a way that i can append a name to the cache name used to cache this page?
It seems it should be easy to hook in the cache rending and change it but i could not find anything helpfull.

Link to comment
Share on other sites

  • 3 weeks later...

The domains go to the same site/server.

I wanted to avoid unnecessary complexity in my template code (i'm just a hobby programmer and more of a designer). Also it allows me to change it from the admin panel, which removes the necessity of re-uploading files.

But i see that your route is a better way to go, then to wait for someone to help me with this niece case.

Sorry for being a bit impatient with things. I can't sit long behind my desk and am long past my deadline, but that's my problem.

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

You where right LostKobrakai, I was to stubborn to really listen and take advantage of your advice.

Reading up about it the first time made it seem like it would work fine in my case, bringing it in to practice was a whole other thing. Saving pages to cache resulted in returning only id's after saving and sometimes a piece of code worked but a minute later it didn't, so i got really frustrated and  just gave up after a while.

I took a fresh look a few days later and I could fix the id problem (LazyLoading) by using $pages->findOne instead of $pages->get. Also i noticed pages where being cached somehow even if i turn it off by using  // FileCompiler=0 in the top of the file, or using the following in config.php

$config->debug = true;
if ( $config->debug == true ) {
    $config->fileCompilerOptions = array(
        'siteOnly' => false,
        'showNotices' => true,
        'logNotices' => false,
        'exclusions' => array('php', 'phtml'),
        'extensions' => array('php', 'module', 'inc', 'phtml'),
    );
    $config->dbCache = false;
    $config->moduleCompile = true;
    $config->templateCompile = false;
}


Strangely the error page show's the updated code but still thinks there is an error.
http://i.imgur.com/Dx1B0x0.png

So i'm sorry for my little outburst in the comment above. Although it seemed simpler to set the secondaryID in my mind, this solution is a whole lot more powerful.

Link to comment
Share on other sites

You disabled everything for the fileCompiler, but wireCache and the fileCompiler are two totally different things. The first one is a multiple purpose cache for data you handle in your code. The fileCompiler is there to dynamically add the ProcessWire namespace needed in php files since pw 3.0, a.k.a. it's literally changing your php files and is not a cache for data at all.

You could do this:

// in config.php
$config->cacheTimeMultiplier = 1
if($config->debug) $config->cacheTimeMultiplier = 0

// elsewhere
echo $cache->get("hello-world", 3600 * $config->cacheTimeMultiplier, function() {
  echo "<p>Hello World</p>";
}); 

 

  • Like 2
Link to comment
Share on other sites

I commented out the wire cache during testing (by commenting out the code), so no problem there. Thanks for letting me know the filecompiler stuff is unnecessary, i already namespace my files so it's only needed for modules.

I already gave up on the cache problem.

edit: grasping at straws

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...