asm89 / twig-cache-extension

The missing cache extension for Twig. Caching template fragments with Twig.
MIT License
388 stars 27 forks source link

500 error in embedded controller gets cached in prod mode? #25

Closed EdwardIII closed 8 years ago

EdwardIII commented 9 years ago

When running in dev mode with debug off, this works as I'd expect:

{% cache 'v1/blog' ~ pageNumber 900 %}
    {{ render(controller('AppBundle:Default:_blog', {'pageToken': pageToken, 'pageNumber': pageNumber})) }}
{% endcache %}

If an exception gets thrown inside that controller then it bubbles up as 500 and nothing gets cached.

However, when I switch to prod mode with debug off I seem to just get a blank 200 page back if an underyling exception occurs. Then it seems to stay cached.

These are the objects I'm using:

app.cache_backend:
    class: Doctrine\Common\Cache\ApcCache

app.cache_provider:
    class: Asm89\Twig\CacheExtension\CacheProvider\DoctrineCacheAdapter
    arguments: ['@app.cache_backend']

app.lifetime_cache_strategy:
    class: Asm89\Twig\CacheExtension\CacheStrategy\LifetimeCacheStrategy
    arguments: ['@app.cache_provider']

app.cache_extension:
    class: Asm89\Twig\CacheExtension\Extension
    arguments: ['@app.lifetime_cache_strategy']
    tags:
        - { name: twig.extension }
asm89 commented 8 years ago

@EdwardIII Were you able to solve/workaround this? I'm not sure if the dev/prod difference is because of this extension or because of Symfony (?).

EdwardIII commented 8 years ago

I've just created a fresh project with the latest 1.x version of your project and the latest stable symfony and I can't seem to replicate it. Not sure if it was a bug with older versions or whether something was wrong our implementation. Either way, no longer seems to be a problem.

Just to confirm, when we throw an exception in a controller in prod mode now, with this config (the one above), we see 500 in the browser as expected.

asm89 commented 8 years ago

:+1: Let's close this issue out then. If you see the behavior again feel free to re-open.