Link to home
Start Free TrialLog in
Avatar of waffe
waffeFlag for United States of America

asked on

How to refresh database cached data?

Hi,

I am loading information form a database and caching the data with this script:
http://developer.yahoo.com/php/howto-cacheRestPhp.html

I them run the website of the cache instead of queering the server everytime.

What I want to do is have this data refresh a few times a day regardless if a user shows up or not. Currently the cache will only reload if a user goes to a page where the data is used and if the data is over 2 hours old. I feel cron might work here but don't know how to call a web page without a user going to it... or if that's even proper. Any ideas?

Thanks,
waffe
SOLUTION
Avatar of giltjr
giltjr
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of waffe

ASKER

giltjr:
My thoughts are that if a single page holds the key to the entire site being updated and no one goes to that page then data on other pages that users could go to will never get updated.

But your right, I could easily make the refresh 1 a week. The only problem with that is when the owner updates that database the cached data (live web site) would not updated for up to a week.

Thanks,
waffe
I'm confused.  You are now saying there is a single page that causes the whole site to be updated.  Whereas in your original post you stated the data on a page would be updated whenever somebody went to that page.

So which is it, a single page that causes all data to be refreshed, or each page causes a refresh for the data displayed on that page?

If it is a single page that updates everything, the I would suggest some changes.

How old would you accept the data to be: 5 minutes, 10 minutes, 1 hour or something else?
Avatar of waffe

ASKER

It's a single page that causes all data to be refreshed.

The data could be up to 6 hours old, but thinking about it more I could create a page that the owner goes to after they update the database that refreshes the data. That way the cache is only updated when it's actually needed.

Thanks,
waffe
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of waffe

ASKER

"You change the site so that each page executes a PHP"
That's basically in the first link that I posted, the problem is the data I'm using is not on just on one page so there might as well be a master database for all the pages.

"modify the application that updates the data" - that would be great but the application is not in my control.

I'm going to go with a page that the owner goes to after they update the database; that will in turn, update the cache. I may also use a cron setup that will execute a php file as leakim971: mentioned and set it to once a month / week.  ]

Thanks,
waffe
--> ... I'm using is not on just on one page ....

Maybe I'm missing something, but why can all pages be updated to trigger a refresh?

Is there any reason that you don't just read the database directly so you can get rid of the caching issue?
Avatar of waffe

ASKER

To ask the server if the data has been updated is not an option because I do not have control over the server. So there is know to ask the server if the data has been changed. With the cache link I posted the queried data is put into the cache with a timer that will trigger after a set amount of time and then someone comes to the page.

I do not  just read from the database because the company I am working with asked me not to and pointed me to the cache link above. And second, I have to re-order the data in such a way that will work better with website design.
Thanks for the points.

Just to clear something up, I did not mean to ask the server, what I meant was that the PHP scripts that does the refresh as some code added that sets a variable (say lastrefresh) to the time of the last refresh.  When the script starts is checks this variable and if the current time is more than "x" minutes from the last time, then it actually does the refresh, if it is less than "x" minutes, it does not do the refresh.