Post by Joe1234 » Sun Dec 15, 2024 4:23 am

I have one particular mod that I don't want to cache, I did some searches and didn't see a clear way to stop the caching of one particular mod. So I put the following at the top of my controller:

Code: Select all

		session_start();
		if (!isset($_SESSION['refreshed'])) {
			$_SESSION['refreshed'] = true;
			echo '<script type="text/javascript"> window.location.reload(true); </script>';
			exit();
		}
I did javascript because chrome wasn't playing nicely with the php version. Something is telling me that there is a better way to do this so I don't have to refresh the page. So is there?

v3.0.4.0 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by ADD Creative » Sun Dec 15, 2024 9:06 pm

What cache are you trying to stop?

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by Joe1234 » Sun Dec 15, 2024 10:22 pm

I don't really understand the question. But i have mod that does something in the database when the visitor lands on the page. But it only works once unless the page is refreshed.

v3.0.4.0 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by JNeuhoff » Sun Dec 15, 2024 11:30 pm

Joe1234 wrote:
Sun Dec 15, 2024 10:22 pm
I don't really understand the question. But i have mod that does something in the database when the visitor lands on the page. But it only works once unless the page is refreshed.
Seriously, you have been a member of this forum for long enough to know that, if you want some help here, you have to provide some more details.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member
Online

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by ADD Creative » Sun Dec 15, 2024 11:38 pm

Sounds like a browser cache, but could be a caching proxy or cache extension. What are the Cache-Control and Expires headers set to for that page? Use your web browser developer tool to find out.

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by Joe1234 » Mon Dec 16, 2024 3:03 am

@JNeuhoff, I appreciate you always helping, but you always say the same thing. I provide all the info that I have or think is needed. If there is something more specific that you think is necessary, then ask for it and I will provide it if I have it. I don't know what I don't know. But each time others are able to provide what I need, or help me think in a different way to resolve the issue with the info that I provide that you say is not enough, so I don't understand what you are asking for. Like in this situation, I have no idea what more you could need; I'm asking if there is something that I can do differently than what I have to achieve the same goal, and I'm showing you what I have...it's clear to me. ADD understood the issue with the provided info and was able to point me to where I was thinking differently and play around to figure things out. So just tell me what you need and I'll get it, otherwise I'm only able to give what I think I got.

@ADD Creative, The Cache-Control and Expires is set to 5 days out which is in alignment with my htaccess.

I figured out exactly what I needed and put this at the top of the controller which fixed the issue...but I swear I tried doing it before but ended up with a 500 error which lead me to doing the other thing.

Code: Select all

		header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
		header("Expires: Thu, 01 Jan 1970 00:00:00 GMT");
		header("Pragma: no-cache");
		
Also, in playing around with the code, I see I don't need the javascript reload, all I need is "session_start();". Out of curiosity, will that affect the session that OC establishes?

v3.0.4.0 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by ADD Creative » Mon Dec 16, 2024 3:37 am

PHP will set the Cache-Control and Expires headers when session_start is called, with nocache being the default.
https://www.php.net/manual/en/function. ... imiter.php

In OpenCart 3.0.4.0 the headers have been set for all PHP generated responses.
https://github.com/opencart/opencart/co ... cde37f9f11

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by paulfeakins » Mon Dec 16, 2024 8:06 pm

Joe1234 wrote:
Mon Dec 16, 2024 3:03 am
I don't know what I don't know.
Even so, I agree with Jeff - you've been here long enough to know you should be more specific and provide more information. In this case for example OpenCart has several caches - vQmod cache, OCMOD cache, twig cache, browser cache etc. etc. You didn't tell us which one you wanted to avoid. The golden rule is be really specific.

Joe1234 wrote:
Mon Dec 16, 2024 3:03 am
I figured out exactly what I needed
I will mark this [SOLVED].

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Legendary Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by nonnedelectari » Mon Dec 16, 2024 8:33 pm

Joe1234 wrote:
Mon Dec 16, 2024 3:03 am
@JNeuhoff, I appreciate you always helping, but you always say the same thing. I provide all the info that I have or think is needed. If there is something more specific that you think is necessary, then ask for it and I will provide it if I have it. I don't know what I don't know. But each time others are able to provide what I need, or help me think in a different way to resolve the issue with the info that I provide that you say is not enough, so I don't understand what you are asking for. Like in this situation, I have no idea what more you could need; I'm asking if there is something that I can do differently than what I have to achieve the same goal, and I'm showing you what I have...it's clear to me. ADD understood the issue with the provided info and was able to point me to where I was thinking differently and play around to figure things out. So just tell me what you need and I'll get it, otherwise I'm only able to give what I think I got.

@ADD Creative, The Cache-Control and Expires is set to 5 days out which is in alignment with my htaccess.

I figured out exactly what I needed and put this at the top of the controller which fixed the issue...but I swear I tried doing it before but ended up with a 500 error which lead me to doing the other thing.

Code: Select all

		header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
		header("Expires: Thu, 01 Jan 1970 00:00:00 GMT");
		header("Pragma: no-cache");
		
Also, in playing around with the code, I see I don't need the javascript reload, all I need is "session_start();". Out of curiosity, will that affect the session that OC establishes?
adding:

Code: Select all

$response->addHeader('Cache-Control: no-store');
after:

Code: Select all

$response = new Response($registry);
in system/framework.php
will suffice to ensure that output generated by the response class (i.e. all dynamic content) is not cached in any shared and private caches.
All the other directives are lesser controls and/or redundant and thus futile when no-store is used.
PS. no-cache is a misnomer as it doesn't mean "don't cache", it is actually the same as "must-revalidate".

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm
Who is online

Users browsing this forum: Semrush [Bot] and 20 guests