PhpCahe

Discussion in 'PHP' started by newzone, Sep 23, 2010.

  1. #1
    I'm trying to use this free script PhpCache: http://codingrecipes.com/phpcache-a-simple-powerful-object-caching-solution-for-php-applications

    This is the example configuration file:

    require_once 'phpcache.class.php';
     
        $database = array(
            'type'  => 'mysql',
            'name'  => 'YOUR DATABASE NAME',
            'table' => 'PHPCache',
            'user'  => 'YOUR DATABASE USERNAME',
            'pass'  => 'YOUR DATABASE USERNAME\'S PASSWORD',
            'host'  => 'localhost' /* Or maybe IP address of your database server */
        );
     
        PHPCache::configure($database);
        $cache = PHPCache::instance();
     
        if( ($results = $cache->get('result_of_some_nasty_code')) !== false ) {
            $tpl->assign($results);
            /* Or maybe return $results or whatever depending on where you use this */
        } else {
            /***********************
             * Your slow code here
             ***********************/
     
            $cache->store('result_of_some_nasty_code', $results_of_your_slow_code, PHPCACHE_1_HOUR * 5); /* Cache for 5 hours */
        }
    PHP:
    I uploaded everything, created the database but I'm receiving this error:
    Line 26 is this:
        $tpl->assign($results);
    
    PHP:
    Any solutions to make the script work?
     
    newzone, Sep 23, 2010 IP
  2. axelay

    axelay Peon

    Messages:
    54
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Think this is something you actually need to change.
    $tpl could be short for $template and you might only want to return the data so this would not apply in your context. It may well be from the author's site and he didn't pay much attention to his code.

    aXe
     
    axelay, Sep 23, 2010 IP
  3. imperialDirectory

    imperialDirectory Peon

    Messages:
    395
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Just a suggestion. If you use Windows server, try WinCache module. If you use Linux server, try MemCache module. Both use memory cache instead of file cache or database cache. Also it supports op cache which caches your PHP scripts so they don't need to be parsed every time it runs.
     
    imperialDirectory, Sep 23, 2010 IP