Welcome Guest, Not a member yet? Register   Sign In
Need for Cache Helper?
#1

[eluser]BayssMekanique[/eluser]
I find that in most installs, I am building a controller (mostly for development), to handle the page caching, and in every instance I am building very similar functions. I typically have 1 function which converts the contents of the cache (names and some MIME data) into an array with some light header string parsing. Another function which performs the MD5 hashing on a URI string. And a few modification functions for removing cache files (both clear all, and selectively based on array). I also plan on writing a function for removing older cache files, and modifying the removal tool to also allow a MIME type

Would it be worth my time to compile these into a helper file? Are there any suggestions for features?

**EDIT: I should be more specific, I am talking about a method of controlling the Output cache. I understand that the Caching class exists and has it's own methods, but I am referring to the Output class caching method which writes output caches to files. Resetting this cache is troublesome, and it's very difficult to only reset a subset of the cached files, so a few functions that help perform some common tasks seems like they would be appropriate as a helper.
#2

[eluser]XMadMax[/eluser]
hey Bayss, better to be in a single library file, but if you have ever the same similar functions, would be better to make a Cache_Controller. All your controllers that need cache, can extend from this.

I have a magic method, where any method inside a controller that does not exists, and exists a method as '_{method_name}', means that this method can be cached.

Example:

Calll: /test/method01
If found '_method01' inside test.php, then means that this method can be cached.

Cache_Controller can take care of this with: if(method_exists($this, '_'.$methodName))

Example:
Code:
class Test extends Cache_Controller {
.....
function _mehtod1($params) {
....
}
Code:
class Cache_Controller extends CI_Controller
{
  function __call($methodName, $arguments)   {
     $cachemethod = false;
     if(method_exists($this, '_'.$methodName))   {
         $cachemethod = true;
          // check cache, if available, get cache in $result, else:
                $result = call_user_func_array(array(&$this, '_'.$methodName), $arguments);
     }
     else
         $result = call_user_func_array(array(&$this, $methodName), $arguments);

    if ($cachemethod )
        // Write cache

    return $result;
  }
}



Hope it helps.





Theme © iAndrew 2016 - Forum software by © MyBB