JosephSilber / page-cache

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

multidomain Cache #99

Open MazzMazz opened 2 years ago

MazzMazz commented 2 years ago

Is it Somehow possible to make a subdirectory for the cache? We serve multiple domains via one laravel Project.

e.g. testsite1.de, testsite1.at, testsite1.com

unfortunately the index file is always overwritten and/or serves the wrong website.

lukasreusch commented 2 years ago

We are facing the same challenge.

JohnDotOwl commented 2 years ago

Any updates on this?

michaellindahl commented 2 years ago

If you are not caching the routes in production, you can have each domain have it's own page cache using the following command:

use Silber\PageCache\Cache as PageCache;
app()->make(PageCache::class)->setCachePath($folder);

This works well if you have a separate routes/domain.php file per domain rather than using the default routes/web.php. Just at that command to the top of each routes file.

Update: While this seems like it should work, I'm seeing the cache path only being able to be overridden for one location. I also looked into building multiple middleware, using an anonymous function to create an instance of CacheResponse with it's own Cache object, but this also was tricky. I think the best option here is to add the ability to provide a path as a middleware parameter.