Post by conandrum » Sun Nov 03, 2019 9:17 am

I have created a small extension module, which includes only a single button which does a 302 redirect.
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');
2. AND Precede every $this->response->redirect(...) with :

Code: Select all

header("Cache-Control: no-cache, no-store, must-revalidate"); header("Pragma: no-cache");
In this way, I am absolutely sure that anyone using my extension will not see any caching no matter what they have in their .htaccess, and I will not face any support issues on the matter and I will not have to ask them to change anything in order for my extension to work on their system.
That's it!

Attachments

Last edited by conandrum on Mon Nov 04, 2019 1:34 am, edited 4 times in total.

New member

Posts

Joined
Tue Jul 09, 2013 6:10 pm

Post by letxobnav » Sun Nov 03, 2019 9:23 am

Code: Select all

If you also have $this->response->redirect in your module, adding headers before the redirect has NO EFFECT!
that is because $this->response->redirect does just that, redirect, it produces no output other than a location redirect 302 header

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by conandrum » Sun Nov 03, 2019 9:27 am

letxobnav wrote:
Sun Nov 03, 2019 9:23 am
that is because $this->response->redirect does just that, redirect, it produces no output other than a location redirect 302 header
That's just beautiful - but why is my browser caching it?
letxobnav does your browser cache your 302 from oc 3.x? OC 2.3 does not do that for me.

LOOK: Status Code: 302 Found (from disk cache)
This is not good!!

Are you saying that with OC 3.x the only solution is to give up on text/html caching?
I do not want the browser to cache my 302 redirects!!! I want to control my redirects in 3.x. How do I do that?

New member

Posts

Joined
Tue Jul 09, 2013 6:10 pm

Post by letxobnav » Sun Nov 03, 2019 9:58 am

Are you saying that with OC 3.x the only solution is to give up on text/html caching?
You should never cache dynamically generated html on any site.
I do not want the browser to cache my 302 redirects!!!
a browser never caches 302 redirects, in fact, it only caches 301 redirects.

stop drawing conclusions on wrong assumptions.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by conandrum » Sun Nov 03, 2019 10:01 am

a browser never caches 302 redirects, in fact, it only caches 301 redirects.
stop drawing conclusions on wrong assumptions.
Well, if you do not believe me just download and install the cache_tester module from my first post and see for yourself.
I am not here to joke around.
My browser is actually caching the 302 as you can see from my previous post.

New member

Posts

Joined
Tue Jul 09, 2013 6:10 pm

Post by conandrum » Sun Nov 03, 2019 10:09 am

a browser never caches 302 redirects, in fact, it only caches 301 redirects.
stop drawing conclusions on wrong assumptions.
Well, if you do not believe me just download and install the cache_tester module from my first post and see for yourself.
I am not here to joke around.
My browser is actually caching the 302 as you can see from my previous post.
Or see the screen shot attached

Attachments

2019-11-03_04-05-18.png

2019-11-03_04-05-18.png (286.25 KiB) Viewed 5617 times


New member

Posts

Joined
Tue Jul 09, 2013 6:10 pm

Post by conandrum » Sun Nov 03, 2019 10:19 am

On the contrary, OC 2.x somehow manages to add a 'Cache-Control: no-store, no-cache, must-revalidate' header in relation to the 302 redirect.
How this is done is a mystery to me, but you can clearly see it in the screenshot below.

Attachments

OC2.X.png

OC2.X.png (100.16 KiB) Viewed 5614 times


New member

Posts

Joined
Tue Jul 09, 2013 6:10 pm

Post by conandrum » Sun Nov 03, 2019 10:32 am

letxobnav wrote:
Sun Nov 03, 2019 9:58 am
Are you saying that with OC 3.x the only solution is to give up on text/html caching?
You should never cache dynamically generated html on any site.
Bear in mind that 'ExpiresByType text/html' does not actually === dynamically generated html.
I will actually have to give up on all the static text/html caching on my site in order to cater for the OC 3.x way of doing things.

This is a negative in my book, but I can see that there is no way around it and I will have to go down this road.

New member

Posts

Joined
Tue Jul 09, 2013 6:10 pm

Post by letxobnav » Sun Nov 03, 2019 11:55 am

'ExpiresByType text/html' does not actually === dynamically generated html.
Don't understand this sentence.
static text/html caching
there is no static text/html caching, there is only a header which states to the browser that any url containing html it receives has a certain expiration date/time and until that date/time is reached it can use the one it already has. Nothing to do with static/dynamic. The browser does not know the difference.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by conandrum » Sun Nov 03, 2019 10:53 pm

letxobnav wrote:
Sun Nov 03, 2019 11:55 am
'ExpiresByType text/html' does not actually === dynamically generated html.
Don't understand this sentence.
letxobnav wrote:
Sun Nov 03, 2019 9:58 am
You should never cache dynamically generated html on any site.

...Nothing to do with static/dynamic. The browser does not know the difference.
There you go. You answered your question yourself.
Exactly because the browser does not know the difference, you cannot define a 'ExpiresByType "access plus 0 seconds"' directive only for the 'dynamically generated html' while allowing the 'static html' to be cached.
Therefore your statement 'You should never cache dynamically generated html', makes no sense in the 'ExpiresByType' context.
It does however make sense for the CMS generating the 'dynamically generated html'.
It should be the CMS's job to set the right headers overriding any 'ExpiresByType' directives you may have in place in your .htaccess.
This was perfectly done in OC 2.3, but OC3.x is messing up here because it allows the 302 to be cached - and it will not be cached ONLY if you stop caching ALL your text/html content from htaccess.

New member

Posts

Joined
Tue Jul 09, 2013 6:10 pm

Post by letxobnav » Sun Nov 03, 2019 11:16 pm

You should never cache dynamically generated html on any site.
means that you should never let the browser cache whatever html is produced by OC response class as that is always dynamic.
I told you this before.
You answered your question yourself.
I did not ask a question.
Therefore your statement 'You should never cache dynamically generated html', makes no sense in the 'ExpiresByType' context.
makes perfect sense, you should either not use expire headers for type html and not use expiredefault or have it expire explicitely in the past or immediately
but OC3.x is messing up here because it allows the 302 to be cached
no browser caches 302 redirection headers, there is nothing to cache, I told you this before as well.
As I said before you are making conclusions based on wrong assumptions due to lack of knowledge of how headers and browsers work.
and it will not be cached ONLY if you stop caching ALL your text/html content from htaccess
which you should where browser caching is concerned as I have told you many times now.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by conandrum » Sun Nov 03, 2019 11:45 pm

No use arguing. I think the issue is summed up perfectly in my last post.

Let's bring new info to the table. You said:
no browser caches 302 redirection headers, there is nothing to cache, I told you this before as well.
As I said before you are making conclusions based on wrong assumptions due to lack of knowledge of how headers and browsers work.
https://www.google.com/search?q=302+cac ... e&ie=UTF-8
Seems to me that 302 browser caching is a common problem.
Here is a quote:
a 302 redirect with an expiration date in the past shouldn’t be cached. The official ruling can be found in RFC 2616.
from https://www.stevesouders.com/blog/2010/ ... deep-dive/
You can test your 302 caching here:
http://stevesouders.com/tests/redirects/index.php

I am not making conclusions based on wrong assumptions.
On the contrary it is you making conclusions based on theory, which not always reflects reality.
I have sent you screen shots showing 302 loaded from disk-cache in Chrome - you do not believe it!
I have sent you a module which you can install and test this yourself.... - you did not even download it!
So how can you in all honesty provide any help as a scientist, if you do not run the tests yourself?
You cannot!
Science is based on empirical evidence. I provided my evidence and the litmus test to help you replicate the problems.
Replicate! Convince yourself!
Repeating what the choir already knows is not helping anybody.
which you should where browser caching is concerned as I have told you many times now.
Saying something many times does not make it true.
Do you really wanna help me?
Here is what I want )))
1. I wanna keep my text/html cached for 15 minutes as I was doing with OC 2.3
2. I want OC 3.x to send headers/cookies/past_expiration_date/whatever overriding the above directive whenever it does a 302 redirect.
Can you help?

New member

Posts

Joined
Tue Jul 09, 2013 6:10 pm

Post by letxobnav » Mon Nov 04, 2019 12:16 am

ok, you do not want to argue and then do it anyway.

I am programming web services now for more than 15 years so I am a little past the "theory" phase.
But I cannot help someone who does not grasp the basic concepts of http and more importantly does not listen.

Blindly looking at information without having the faintest idea of what it actually means and forms conclusions on that.
The fact that a mere google search on "302 cached" yields results already has you convinced you have a point.
I assure you that googling "aliens in Manhattan" also yields results.

so, I can only say, good luck.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by conandrum » Mon Nov 04, 2019 12:27 am

I gave
1. empirical evidence
2. a test you can replicate
3. testimonies from experts on browser redirection.

You have to understand that browsers do cache 302 redirection.
If you do not, you cannot help no matter how many years you have been developing.

New member

Posts

Joined
Tue Jul 09, 2013 6:10 pm

Post by conandrum » Mon Nov 04, 2019 1:38 am

letxobnav wrote:
Mon Nov 04, 2019 12:16 am
so, I can only say, good luck.
Thank you for your kind words letxobnav. As soon as you wished me good luck, it came from ADD Creative!
God bless you )))
I have outlined the solution in my 1st post in this thread.

New member

Posts

Joined
Tue Jul 09, 2013 6:10 pm
Who is online

Users browsing this forum: No registered users and 51 guests