JosephSilber / page-cache

Caches responses as static files on disk for lightning fast page loads.
MIT License
1.21k stars 118 forks source link

Proposal: Adding the possibility of use in projects with different domains. #59

Closed mlg1 closed 4 years ago

mlg1 commented 4 years ago

Hello, By changing one line, functionality can be added to use the plugin with different domains.

In the file src/Cache.php on line 198:

- $segments = explode('/', ltrim($request->getPathInfo(), '/')); + $segments = explode('/', ltrim($request->getHost() . $request->getPathInfo(), '/'));

It has been tested on Laravel 7 and it works for me. Is it a good idea? Is there something I'm missing?

mlg1 commented 4 years ago

I also forgot to add the .htaccess file.

# Serve Cached Page If Available...
RewriteCond %{REQUEST_URI} ^/?$
RewriteCond %{DOCUMENT_ROOT}/page-cache/%{HTTP_HOST}/pc__index__pc.html -f
RewriteRule .? page-cache/%{HTTP_HOST}/pc__index__pc.html [L]
RewriteCond %{DOCUMENT_ROOT}/page-cache/%{HTTP_HOST}%{REQUEST_URI}.html -f
RewriteRule . page-cache/%{HTTP_HOST}%{REQUEST_URI}.html [L]
RewriteCond %{DOCUMENT_ROOT}/page-cache/%{HTTP_HOST}%{REQUEST_URI}.json -f  
RewriteRule . page-cache/%{HTTP_HOST}%{REQUEST_URI}.json [L]
JosephSilber commented 4 years ago

This would break all existing caches.

If you want this in your project, you can easily extend the built-in Cache class, and overwrite that method :+1:

MarcosBL commented 3 years ago

You can also do it setting a different path depending on domain at boot on AppServiceProvider

Look here https://github.com/JosephSilber/page-cache/issues/74#issuecomment-883701867