pug-php / pug

Pug template engine for PHP
https://www.phug-lang.com
MIT License
391 stars 42 forks source link

Pug-PHP 3: Cache only stores first page accessed #166

Closed wolfgang42 closed 7 years ago

wolfgang42 commented 7 years ago

I've upgraded to version 3.0.0-beta1, and discovered that the cache function seems to be broken: whichever file gets rendered first (using $pug->renderFile()) is cached and served in place of every other file rendered! Only one file is ever stored in the cache directory; its name is invariably z4PhNX7vuL3xVChQ1m2AB9Yg5AULVxXcg_SpIdNs6c5H0NE8XYXysP-DGNKHfuwvY7kxvUdBeoGlODJ6-SfaPg.php no matter what the name or contents of the rendered file was.

kylekatarnls commented 7 years ago

I don't reproduce your issue, I wrote the following test to ensure uniqueness of cache paths: https://github.com/pug-php/pug/commit/2d9c0295daa93e0cac7fd183a897b7626defa25a#diff-945ec87e88dece5c876a0b0605d927e0R128

And the test passed successfully on every supported PHP versions.

As you can see, I enable the cache, then I cache basic.pug, case.pug and basic.pug again.

I get, 1, 2 and 2 files in the cache directory used. That seems to be the expected behavior.

Are you sure, you do not copy the file in an intermediate path?

wolfgang42 commented 7 years ago

Aha, it seems that this only happens when renderFile is passed a path relative to basedir. If an absolute path is given then the caching occurs correctly. Minimal repro:

<?php
require __DIR__.'/../vendor/autoload.php';
use Pug\Pug;
$pug = new Pug([
    'basedir' => __DIR__.'/../views/',
    'cache' => '/tmp/',
]);
echo $pug->renderFile('docs');
echo $pug->renderFile('index');

Expected result is docs.pug followed by index.pug, but instead I get two copies of docs.pug.

kylekatarnls commented 7 years ago

Thanks for your test case, I reproduced it in unit tests. Soon fixed.

kylekatarnls commented 7 years ago

Hi, I fixed it in https://github.com/phug/renderer, you can update with composer update to get the last version working with relative paths.

wolfgang42 commented 7 years ago

Thanks, I can confirm that this is now working as expected.