CachedController v1.0 - cache BY OBJECT->METHOD. any method, not all the page by URI |
[eluser]sdbruder[/eluser]
I was toying with a simple HMVC scheme, using real controlers in libraries subdir (it works!), but stumbled in the following dilema: the output cache is by URI, not by controller, its not designed to be multi-controller aware. SO.. Ive made my own Cacheable Controller. It uses the same cache infra-structure, and it caches BY METHOD. Im using what php calls 'overloading' (its not classic overloading, but fit my need here) to create cached versions of any method, so if I want to cache $mycontroller->index() I call $mycontroller->indexCached(); Works for any method. Autoload it, extend your Controller from it and that's it. The same ideia can be easily adapted in other places as well, not only controllers. PS: Not tested under PHP4. First, an obvious example: Ive made a simple menu MVC, one entry in the menu for each file under /PAGES/ subdir (if the page is static, the content of the static page is there). For each page the menu controller scandir('/pages/') {ob_start(); include() it, ob_end_clean() to drop the content if its a static page, etcetera } Wonderfully simple to operate after, but 'costly' to do it every page hit.. So... Code: class Menu extends CachedController { Now the code per se: Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
[eluser]sdbruder[/eluser]
In the current state of this code, its more usable for HMVC folks, IMHO. To be usable & handly for a larger audience, we need to implement it in the load object, in the model, etc. I'll try latter. UPDATE: Ive made a V1.1, now with controller and model cached versions, if anyone is interested I'll upload it UPDATE2: And all of this without system hacking, only extending Controller and Model in your application.
[eluser]Maks Baum[/eluser]
Good job ![]() I was thinking about writing some helper to cache some data, but thank God I used 'search form' Now I only have to extend MY_Controller yours and I'll have everything what I want to have ![]()
[eluser]Maks Baum[/eluser]
[quote author="sdbruder" date="1209736550"] UPDATE: Ive made a V1.1, now with controller and model cached versions, if anyone is interested I'll upload it [/quote] so.... where Can I grab it? ![]()
[eluser]sdbruder[/eluser]
I was busy in the last days finishing my shiny new nerd toy, a fanless mini-itx linux server (1GHz VIA C7 1GB 750GB) to be the time machine target to my macs.. I will upload it tomorrow after some polish, I promise!
[eluser]sdbruder[/eluser]
See: http://ellislab.com/forums/viewthread/81213/ or download it directly: http://sergio.bruder.com.br/cachedobjects/ |
Welcome Guest, Not a member yet? Register Sign In |