barryvdh / laravel-httpcache

Laravel HTTP Cache
484 stars 41 forks source link

Bug/Question - ESI with cache off #1

Open thomaswelton opened 10 years ago

thomaswelton commented 10 years ago

When working and developing locally I want the cache off. I want to make a change to my views and see my changes instantly.

But in production I want caching enabled, and also use ESI includes. Problem being when working locally with cache off the ESI tags are not parsed.

I'm also using Varnish. So what I'd like to get is Local: Caching off, ESI tags parsed to HTML as there is no local Varnish Production: Caching on, ESI tags left alone so Varnish can handle them.

Any help would be appreciated. Is this package suitable for my need, or should I write my own to handle ESI. Thanks.

barryvdh commented 10 years ago

I don't have a lot of experience with Varnish. Do you need this package when you have Varnish? Or do you just want to use this package locally instead of Varnish?

You can use a filter to tweak the response

App::after(function($request, $response)
{
    if(!Config::get('app.debug')){
        $response->setTtl(600);
    }
});

So only make it public when not in dev mode, so it won't be cached (but ESI will be parsed). (Or other way around, make it private when you are in dev)

You can also add the the ServiceProvider only to app/config/local/app.php, so it won't get loaded on production:

'providers' => append_config(array(
    'Barryvdh\HttpCache\ServiceProvider',
)),

Hope this is what you mean?

I can see if it is possible to enable ESI without enabling the cache, but you are free to submit a PR if you want.

thomaswelton commented 10 years ago

Yeah I'd already forked it to try and get ESI to work with caching disabled. Possibly more work than I initially thought. Right now I think I only need this package as it helps with the setting of the cache headers. And parsing of ESI when running outside of Varnish.

I may try to add this as a PR, or create a separate package just to handle ESI parsing. Will keep you updated