Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Each Request creates new static file #79

Open
ghost opened this issue Jun 17, 2021 · 6 comments
Open

Each Request creates new static file #79

ghost opened this issue Jun 17, 2021 · 6 comments

Comments

@ghost
Copy link

ghost commented Jun 17, 2021

After deeply reviewing, I came to find that even if the page has got no change, it keeps updating the cached static html file. (As i see the time of the file)
That is the reason I cannot request the cached page, since it keeps updating.
Please help

@champkris
Copy link

Got this too, anybody got the solution?

@champkris
Copy link

Hi I seems to solve mine.
I have 2 .htaccess, one in /public and another at root /

I have to place the apache mod_rewrite at root but for mine, I need to add /public in the rewrite rule & condition, so it become below:

Serve Cached Page If Available...

RewriteCond %{REQUEST_URI} ^/?$
RewriteCond %{DOCUMENT_ROOT}/public/page-cache/pc__index__pc.html -f
RewriteRule .? page-cache/pc__index__pc.html [L]
RewriteCond %{DOCUMENT_ROOT}/public/page-cache%{REQUEST_URI}.html -f
RewriteRule . page-cache%{REQUEST_URI}.html [L]
RewriteCond %{DOCUMENT_ROOT}/public/page-cache%{REQUEST_URI}.json -f
RewriteRule . page-cache%{REQUEST_URI}.json [L]

@ghost
Copy link
Author

ghost commented Jun 25, 2021

Hi I seems to solve mine.
I have 2 .htaccess, one in /public and another at root /

I have to place the apache mod_rewrite at root but for mine, I need to add /public in the rewrite rule & condition, so it become below:

Serve Cached Page If Available...

RewriteCond %{REQUEST_URI} ^/?$
RewriteCond %{DOCUMENT_ROOT}/public/page-cache/pc__index__pc.html -f
RewriteRule .? page-cache/pc__index__pc.html [L]
RewriteCond %{DOCUMENT_ROOT}/public/page-cache%{REQUEST_URI}.html -f
RewriteRule . page-cache%{REQUEST_URI}.html [L]
RewriteCond %{DOCUMENT_ROOT}/public/page-cache%{REQUEST_URI}.json -f
RewriteRule . page-cache%{REQUEST_URI}.json [L]

Can you please come to me at TG @Laptic

@ghost
Copy link
Author

ghost commented Jun 25, 2021

Hi I seems to solve mine.
I have 2 .htaccess, one in /public and another at root /

I have to place the apache mod_rewrite at root but for mine, I need to add /public in the rewrite rule & condition, so it become below:

Serve Cached Page If Available...

RewriteCond %{REQUEST_URI} ^/?$
RewriteCond %{DOCUMENT_ROOT}/public/page-cache/pc__index__pc.html -f
RewriteRule .? page-cache/pc__index__pc.html [L]
RewriteCond %{DOCUMENT_ROOT}/public/page-cache%{REQUEST_URI}.html -f
RewriteRule . page-cache%{REQUEST_URI}.html [L]
RewriteCond %{DOCUMENT_ROOT}/public/page-cache%{REQUEST_URI}.json -f
RewriteRule . page-cache%{REQUEST_URI}.json [L]

I did the same, it creates the cached file again and again even no update in page

@champkris
Copy link

champkris commented Jun 26, 2021

Does your route or parameters contain any non latin character or space that will produce % sign when urldecoded? eg: having space in your route name or parameters will produce %20, then will cause the .htaccess rule not be able to find the cache file then re-cache it again. The same go to non-latin language in URL. I'm using Thai so I also face the same problem.

Good news is, I have figured out the solution by inserting urldecode() in original cache method.

Here is how I did it:

  1. go to Silber/page-cache/src/Cache.php
  2. in public function cache, just add this line before $this->files->makeDirectory($path, 0775, true, true);
$path=urldecode($path);
$file=urldecode($file); 

so your whole cache function should now look like this:

public function cache(Request $request, Response $response)
{       

        list($path, $file) = $this->getDirectoryAndFileNames($request, $response);
        $path=urldecode($path); // added urldecode to solve specialchar problem
        $file=urldecode($file); // added urldecode to solve specialchar problem

        $this->files->makeDirectory($path, 0775, true, true);

        $this->files->put(
            $this->join([$path, $file]),
            $response->getContent(),
            true
        );
}

Hope this helps.

Also some tips to test if cache is working, you can see significant decrease in request time. But there are more complicated way I also use by playing around with .htaccess in order to solve my problem. This library itself is very simple, I think you are facing the same problem as mine (% sign). Hope applying above code would be able to fix yours.

@ghost
Copy link
Author

ghost commented Jun 26, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant