is there an effective way to clear the cache?

Just starting out? Need help? Post your questions and find answers here.
skinkairewalker
Posts: 120
Joined: Tue Jun 14, 2016 7:17 pm

is there an effective way to clear the cache?

Post by skinkairewalker »

I made a web menu for a customer, he always asks me to make changes to the menu, and every time I update it's a huge problem, because we can't make restaurant customers "know how to clear the browser cache, because most are technology laymen " , is there an effective way to prevent the cache from getting in the way of page refresh done in SB ?
Dirk Geppert
Posts: 282
Joined: Fri Sep 22, 2017 7:02 am

Re: is there an effective way to clear the cache?

Post by Dirk Geppert »

There are many browsers out there, with different ways to clear the cache.
Perhaps it is better not to cache certain files or to keep giving them new names during deployment. For example, with a timestamp...
Just as an idea...
KianV
Posts: 21
Joined: Sun Nov 17, 2019 11:38 am

Re: is there an effective way to clear the cache?

Post by KianV »

I don't know if it would be suitable for your application, but inserting:

Code: Select all

!window.location.reload(true);
should force a reload, ignoring the cache.
skinkairewalker
Posts: 120
Joined: Tue Jun 14, 2016 7:17 pm

Re: is there an effective way to clear the cache?

Post by skinkairewalker »

KianV wrote: Sun Jun 27, 2021 3:52 pm I don't know if it would be suitable for your application, but inserting:

Code: Select all

!window.location.reload(true);
should force a reload, ignoring the cache.
how can i use this ? when I try to use it, the page keeps reloading infinitely, is there a way to stop this command from running?
Dirk Geppert wrote: Sun Jun 27, 2021 9:33 am There are many browsers out there, with different ways to clear the cache.
Perhaps it is better not to cache certain files or to keep giving them new names during deployment. For example, with a timestamp...
Just as an idea...
I've tried it, but it didn't work :c
KianV
Posts: 21
Joined: Sun Nov 17, 2019 11:38 am

Re: is there an effective way to clear the cache?

Post by KianV »

skinkairewalker wrote: Sun Jun 27, 2021 8:15 pm how can i use this ? when I try to use it, the page keeps reloading infinitely, is there a way to stop this command from running?
It needs to be triggered by an Event in the program. This could be clicking on something or when any graphics are finished loading &c..
When this should happen depends very much on the program itself, and when it would be most appropriate.
skinkairewalker
Posts: 120
Joined: Tue Jun 14, 2016 7:17 pm

Re: is there an effective way to clear the cache?

Post by skinkairewalker »

KianV wrote: Mon Jun 28, 2021 4:00 am It needs to be triggered by an Event in the program. This could be clicking on something or when any graphics are finished loading &c..
When this should happen depends very much on the program itself, and when it would be most appropriate.
do u have some code example ?
KianV
Posts: 21
Joined: Sun Nov 17, 2019 11:38 am

Re: is there an effective way to clear the cache?

Post by KianV »

Without seeing exactly what your code does, it is difficult to say, but the following should work under all circumstances.

Code: Select all

OpenWindow(0, 100, 100, 320, 200, "Window 0")
TextGadget(0, 10,  70, 300, 20, "This is just to put something on the screen", #PB_Text_Center )

ismenuupdated.s=""
!var v_ismenuupdated = sessionStorage.getItem("pageupdated"); 
;retrieve value from sessionStorage
If ismenuupdated="True"
  Debug "it is already updated"
Else
  Debug "updating the page now"; if value retrieved is not 'True", reload window ignoring cache
  !window.location.reload(true);
  !sessionStorage.setItem("pageupdated", "True");
  ;set value in sessionStorage To 'True'
EndIf

; Put the rest of your code here

Procedure CloseWindowEvent()
  Debug "Closing window: " + EventWindow()
  CloseWindow(EventWindow()) ; Close the specific window
EndProcedure

BindEvent(#PB_Event_CloseWindow, @CloseWindowEvent())
This stores a value in sessionStorage to show that the reload has been done.
The value is stored as long as the window/tab is open. Therefore, when someone comes back to the page again, the value will be lost and the reload will be performed.
I suspect that many people keep the browser on their phones open nearly permanently, so I would suggest putting something at the end - when changing page or checkout or somesuch - to clear the value, just in case.
e.g. !sessionStorage.setItem("pageupdated", "False");
Stefan
Posts: 160
Joined: Mon Feb 05, 2018 9:44 pm

Re: is there an effective way to clear the cache?

Post by Stefan »

The problem ist, that "!window.location.reload(true);" not really good works.
User avatar
William Van Hoecke
Posts: 50
Joined: Tue Oct 22, 2019 12:09 pm

Re: is there an effective way to clear the cache?

Post by William Van Hoecke »

skinkairewalker wrote: Sun Jun 27, 2021 2:05 am I made a web menu for a customer, he always asks me to make changes to the menu, and every time I update it's a huge problem, because we can't make restaurant customers "know how to clear the browser cache, because most are technology laymen " , is there an effective way to prevent the cache from getting in the way of page refresh done in SB ?
Same problem here...
!window.location.reload(true); does not clear the cache it always reloads the same old page !

did you find a solution ?
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: is there an effective way to clear the cache?

Post by Peter »

It is not enough to reload the HTML page. You must also ensure that the JavaScript is loaded without cache.

If you look at the HTML page generated by SpiderBasic, you will see the following line:

Code: Select all

<script type="text/javascript" src="spiderbasic.js"></script>
(spiderbasic.js can also have a different name, depending on what you have called your app)

This file must be reloaded bypassing the cash. If the SpiderBasic compiler appended a timestamp to the JavaScript file each time it generated the HTML file, this wouldn't be a problem.

I asked Fred in 2017 to build this into SpiderBasic; unfortunately without success until today: Attach a timestamp to the generated JavaScript
Post Reply