Caching without views? |
[eluser]Sarfaraz Momin[/eluser]
I have a set of controllers where the output is directly echoed from instead of sending it to the views. The templates are dynamic pulled from database so there is no need of any views. The issue is when i enable caching I am able to see a file generated in the cache folder but the next time I refresh the page it comes up blank. In short it does not work. I have to disable caching and delete the cache file to make the page work again. Am I missing something or is caching available only if we have view files. Please help since today is the deadline for the application to be completed and this is my last module to be implemented.
[eluser]Michael Wales[/eluser]
Uhm... the quickest fix in the world for this is to simply use views: In your controller: Code: $data['template'] = $template; // Put all the template data you pulled from the database here In your view: Code: <?= $template; ?> You could use one view for the entire site. I'm sure you could extend the Caching library to support Controller Caching, although it's pretty much an "F-U" to the MVC concept and would take way to much time and effort. Work smarter, not harder.
[eluser]Sarfaraz Momin[/eluser]
Thanks for the reply. Would just like to know if using one view would cache it properly. I mean to say is that if multiple controllers call the same view will they cache it differently based on the controller data sent to the view or since it is just one view only one file for the cache will be created and updated everytime the view is called in any controller.
[eluser]Michael Wales[/eluser]
I believe the caching is done at the Controller level, not the View, so it would work as you expect it to.
[eluser]Sarfaraz Momin[/eluser]
well one problem which is still bothering me is that if I enable caching will the user info change dynamically for all the users if they login on all the pages. The issue I might face is that once the page is cached the same content will be visible to all the users irrespective of which user is watching it. The method that you explained about using a single view for the complete site would be gr8 but can it give me some more flexibility of caching of the stuff i want it to cache.
[eluser]Michael Wales[/eluser]
You definitely don't want to cache anything that is dynamic. If I am the first to login, it's going to cache my control panel, and every user logging in after me will see my control panel (until the cache expires). There's a library out there that will allow you to only cache certain elements of a page - give me a minute to look around the forums.
[eluser]Michael Wales[/eluser]
Sparks: Caching Template System To be honest, I believe the route your took (by loading templates from the database) is going to hurt you here. I've never used Sparks, so maybe it can help. Maybe just give up on the caching though? Is the application going to receive enough hits that caching is necessary?
[eluser]Sarfaraz Momin[/eluser]
The site is reaching 22K uniques now and is expected to reach 100K uniques in next 4-5 months. Caching is required. I think you are correct. I think i can do one thing. Since i have a CMS I can write the template data in database and also in view files which can help since the view files will be available for the controllers to use. I also came across SPARK which i think can be a good option in my case where i require not to cache some part of my page. If you can get me some good optimization tips for the site it would help. Thanks for your help in this regards.
[eluser]Michael Wales[/eluser]
Yeah - I would write up a real quick PHP script that will query the database and output legitimate view files. Then just convert your code over to use those. Or, another route, not sure how effective it would be: write a cron script that does the same, and run it every X minutes, this way your users are still editing the templates within the database, but the controllers are caching what should be a relatively accurate copy of the database (if it's within the cron timespan).
[eluser]Sarfaraz Momin[/eluser]
My existing template system on the current CMS generates static template files which are then used in the frontend. I can give the users an option to generate the template files whenever they have modified the template files. Might even think of an option like EE of setting template revisions and generate based on the revision selected. Let me try it. I would let you know about the it. |
Welcome Guest, Not a member yet? Register Sign In |