Categories > TinyButStrong general >

How caching system really works?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Ciprian Radu
Date: 2007-04-04
Time: 10:36

How caching system really works?

Hi guys,

I am developing an application, not a static website. But I need a real caching system, because the information in there is very dynamical.

I would need something to convert the TBS template code into php code.

For example, if in the tbs I would have
[var.x]
then in the cache file should be something like:
<? echo $x ?>
in order to be faster.

You know what I mean?

Thank you for your help.



By: Skrol29
Date: 2007-04-04
Time: 13:16

Re: How caching system really works? => compilation

Hi Ciprian,

The technique you're describing is (badly) called template compilation.
In the case of TBS is would be quite difficult to performs template compilation because var and blocks are not pre-asigned, like it is for Smarty for example. This is a choice, and it gives advantages in an other hand.
Nevertheless TBS template compilation could be done for simple templates. But I don't think it exists yet.
By: TomH
Date: 2007-04-04
Time: 14:04

Re: How caching system really works?

Usually caching gives benefits in a situation where there are lots of hits/queries on information that is not changing so fast that the results are changing while the cache is in effect.

What I don't understand is your statement that the information is very dynamic.  If information is changing rapidly -- then wouldn't you need to get the new data to for user? - not show them old data from a cache?

What is the problem that you are trying to fix: ...slow servers because of database thrashing?  ...slow response time because of manipulating very large query result sets? ...or slowdown from very high number of hits/queries in short period of time?

Each of these problems has different solutions depending on the way you need to use the data.

No matter what, if data is VERY dynamic compared to the overall response time for your system - you will have to make a compromise somewhere.

If the main source of the problem is the database queries causing slow response then (IMO) you could make big improvements by using query caching (cache the data results - then render many pages from the cached query data. For that you might us your database engine if it has caching feature -or- (I myself) use ezSQL for query/object caching which is not dependent on the database engine.

If the main source of problem is (not query speed but ) spped up of page displays then it is really easy to solve by using TBS native caching. This feature takes effect in the beginning of .php file so that the time saved includes all time that would be spent doing the php and database work -plus- eliminates all of the time it would take to do the template processing.

If this interests you at all -- there are some examples of different strategies for caching by ezSQL and TBS techniques at http://tomhenry.us/tbs3/

You will find the people on this forum to be very helpful for getting the code to do the job you want -- so just describe some more the problem you have and the code you are using.
By: Ciprian Radu
Date: 2007-04-04
Time: 15:53

Re: How caching system really works?

Hi guys,

Thank you for your replies.

My problem is that I have a pretty huge form, and it takes up to 4-5 seconds to load. First I thought that is a problem with my SQL queries, but I checked and all my script and queries are executed in approximately 1 sec. the other 3-4 seconds are lost in parsing and displaying the template.

Basically the most time consuming is a grid I have in there. Looking like here:

http://pagos.co.uk/public/temp/screen.jpg

the template code for the grid is:
<table cellspacing="0" class="grid">
    <tr>
        <td>&nbsp;[var.selInterests;ope=html;select=interest_1[];noerr</td>
        <td width="50">[gridProjects.val; block=td]</td>
    </tr>
    <tr style="background-color: #CCCCCC">
        <td>[gridData.destination; block=tr]</td>
        <td width="50"><input type="checkbox" class="checkbox" name="interest_1[]" value="[gridData.dest_id]_[gridData.[gridProjects2.key; block=td]]" /></td>
    </tr>
    <tr style="background-color: #FFFFFF;">
        <td>[gridData.destination; block=tr]</td>
        <td width="50" ><input type="checkbox" class="checkbox" name="interest_1[]" value="[gridData.dest_id]_[gridData.[gridProjects3.key; block=td]]" /></td>
    </tr>
</table>

can you tell me what is the best solution in this case?

Thank you.
By: TomH
Date: 2007-04-04
Time: 16:51

Re: How caching system really works?

(1)Seems to me that taking 1 second for the queries is a VERY long time!

But... from the link you show... it seems that you are displaying various categories (from db table fields and maybe from some of the data in those fields)... and from that form the user selections produce a query!

If that is true then the categories that make the form might be fairly static -- compared to the data that is returned after the user makes the form submit -- so the form could be cached (I would use TBS page-cache).

You can find how to do that at the page I showed previously or in the TBS "Examples" section.

That's just for making the empty form - just as you have it shown

Also - for making the form - you could (I would) consider simplifying the application by separating searches:
(a) allow searches by single country for multiple interest selection
(b) allow searches for one  interest area with multiple countries

For returning the results of user selections - see "caching model(3)" ON the previous page reference. This shows how to make caches for a specific combination of db query selections.


(2) The time you report "3-4 seconds are lost in parsing and displaying the template" is almost not believable to me.

You might show ALL the php code for that -- sounds like there's a major problem there, either the form of the query result or the php code.

Will have to see the actual code to help there.



By: TomH
Date: 2007-04-04
Time: 16:58

Re: How caching system really works?

Ooops,

Forgot to include... the table you showed... that is really a very small result for a db query. That should take milliseconds (MySQL) to return the data from a properly indexed db.

Take a look at how the indexing is set for the table(s) you are querying -- maybe there is NO indexes set at all :(

If no indexes - that would be the biggest part of the db response problem.
By: Ciprian Radu
Date: 2007-04-05
Time: 10:45

Re: How caching system really works?

The problem si not from Mysql, I have looked in the profiler, and there are 18 queries executing in maximum one second. My question is why TinyButStrong process the template in another 4 seconds.