For the life of me, I cannot get the redirect to STOP BEING CACHED by the browser!!! Even manually adding headers before the redirection!
Can anybody suggest a solution to this 302 cache problem?
Attached is the module (2 files, controller & twig), play with it.
BACKGROUND:
In my .htaccess file I have the following (some lines removed for brevity):
Code: Select all
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 1 month"
# HTML
ExpiresByType text/html "access plus 15 minutes"
</IfModule>
In OC 3.x, if one does not want their extension to be cached in admin, they have to either:
1. Set: ExpiresByType text/html "access plus 0 seconds" (basically no caching for text/html in OC3.x)
or
2. add $this->response->addHeader('Cache-Control:..') before $this->response->setOutput() or modify framework.php
There is a problem with #2:
If you also have $this->response->redirect in your module, adding headers before the redirect has NO EFFECT!
This means that the only solution in this case is #1, until another solution is found.
SOLUTION:
As stated in this post by ADD Creative.
If you want to keep your .htaccess as is, with a caching timespan for text/html content, but also disable caching from OC 3.x responses & redirects, you can follow the directions in the linked post above.
For myself, as a developer of OC extensions, I have decided to go with option #3 in this post.
So when developing my extensions for OC 3.x I have to remember to :
1. Precede every $this->response->setOutput(...) with :
Code: Select all
$this->response->addHeader('Cache-Control: no-cache, no-store, must-revalidate'); $this->response->addHeader('Pragma: no-cache');
Code: Select all
header("Cache-Control: no-cache, no-store, must-revalidate"); header("Pragma: no-cache");
That's it!