Categories > TinyButStrong general >

Partial caching needed.

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: ege
Date: 2008-11-22
Time: 04:48

Partial caching needed.

Hi there,

Speaking in terms of performance, most of the time a web application's bottleneck is the db connections and queries. That's why caching the html files improves the performance, we all know that.

What I need to do is to cache some parts of the files that I created with tbs. On the current project I work, most important pages use heavy duty db queries but the result of them can be cached. However, the same pages also use some uncachable but light-weight data, such as system-time and name of the logged-in user. So it would be really nice if we can render a template with all those heavy-duty db stuff already merged, but leave some tbs tags intact within the cache file to be processed later. That way, I would load a cache file and just fill [var..now;frm='HH:nn'] and <p>Hello [var._SESSION.user.name;noerr;block=p;magnet=p]</p> and serve the file, without making any queries.

I actually looked at the tbs cache system plugin, read the documentation but didn't see any such functionality, or may be I wasn't creative enough to find my way. Then I tried to implement it myself by modifying the code but I wasn't successful.

What can we do? The question basically targets the tbs author, Skrol, but I guess anybody can help or direct me towards the right way. Any help will be greatly appreciated.

Thanks in advance.
ege.

PS. Also to the attention of Skrol: it would be really useful if you would provide some documentation about the internals of TBS, especially stuff related to plugin development, such as LocR structure.
By: TomH
Date: 2008-11-22
Time: 12:30

Re: Partial caching needed.

ege,

Normally I use the TBS
[var.header_file;script=[val];subtpl]
technique to cache different sections of a page - using the caching in the subtpl as opposed to caching in the main/parent page.

Also, I do use ezSQL plugin as the db class - and ezSQL does provide completely integrated query caching with TBS - which is quite handy in many situations.

I have posted four examples of various TBS caching techniques at http://tomhenry.us/tbs3/ - find the links partway down the page.

Hope that helps,
TomH
By: ege
Date: 2008-11-22
Time: 15:18

Re: Partial caching needed.

Hi Tom,

Thank you for the information.

I understood the way you do it but what I'm after is somehow different. First and foremost, for regular and mid-traffic sites like some portals, I'm inclined to think sql caching is unnecessary since you can cache the resulting html page in its entirety, not only query results. Second, I follow a strictly minimal code and db design, avoiding anything that would complicate a project, and that's why I use tbs in the first place. As such, I kind of think of "subtpl" keyword is evil as it means not only the addition of an extra php file but it also makes it harder to follow the code in a linear fashion, as you have to jump between files to see what's going on. I avoid using subtpl at all costs.

In short, I believe it should be possible to code partial caching mechanism to work unobtrusively. I was thinking of something similar to tbs's caching plugin that would enable you to code something like [var._SESSION.user.name;ope=nocache] or [onload;block=div;ope=nocacheblock] so that the resulting cache files will have small amount of tbs tags to be merged dynamically, when you actually serve the page. I actually tried and was able to implement it for var fields by intercepting the OnOperation event but things got harder for the automatic blocks, especially when they contained "when" or "if" keywords as I wasn't able to get them not processed before I process the block myself. I also couldn't prevent tbs from protecting the [ characters.

Maybe I'm on the wrong path but what I feel is that, in terms of code maintainability, this should be among the best ways to achieve such thing. That would also allow you to write the code without thinking of caching in the first place and once everything is running, you can simply add some small tbs stuff to improve the performance. Although I never used it, I have read that Smarty has similar functionality.