Categories > TinyButStrong general >

Refreshing Cache on db update

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Howman
Date: 2005-07-26
Time: 22:57

Refreshing Cache on db update

Hi,

Part of my website is a directory list that gets updated very infrequently.  The directory data is in MySQL.  I am sure the pages would load a lot faster if they didn't need to hit the database every time.  So caching is a good option.

How can I make the cache refresh ONLY when the database is updated?  Is this even necessary?  Will the caching logic automatically determine that the current cache is still valid and therefore serve the cached static pages?

If it is easier, how do I set a timer to update the cache once a day, say at midnight?

Thank!
Howard
By: Skrol29
Date: 2005-07-27
Time: 15:59

Re: Refreshing Cache on db update

Hello,

You can refresh cache after a duration, or manually. (see CacheAction method). It can also be done automatically when the cache file is absent.

If you whant to refresh only when the database is updated, you will need to  have a way to know if (or when) the database has been updated.
For example, you can simply delete the cache file (using CacheAction() method) when you update the database.

> If it is easier, how do I set a timer to update the
> cache once a day, say at midnight?

See "Cache system" at the example page.
By: Howman
Date: 2005-07-27
Time: 16:21

Re: Refreshing Cache on db update

Hi Skrol.  Thanks for your response.

I think what I am trying to do is different than caching.

Is this how caching logic works?:
- user visits a page
- page determines if cache exists
- if cache exists, is it current
    - if current, display cached page
- if not current, clear cache and display fresh page
    - save fresh page to cache

What I want is:
- cron or some other script calls every page on my site
- the page gets cached
- when user visits the page the cached version is displayed immediately; no logic used to determine current or not

Is there a way to create static pages from dynamic pages?  For example, index.php is dynamic.  You run a script on the server that says, "Run index.php, get the output, open a new file named index,html,  write the page data to index.html, close the new file."  Now your index page for visitors is index.html.  Make sense?

Thanks for your help!
Howard

By: Skrol29
Date: 2005-07-27
Time: 16:56

Re: Refreshing Cache on db update

Hi,

You can merge a template, and then get the contents to do what you want (saving it in a file) instead of displaying it immediatly. This can be done using the Render property.
Thus, you can merge several templates one after each others in a same script, and using the same $TBS instance.

You can additionally play with the Cache System to have it saving the files for you. But this need that you know it a bit.