Zend_Cache backend adapter which store objects in the script's internal memory
PHP
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
samples
src/Application/Cache/Backend
tests
.travis.yml
LICENSE
readme.mdown

readme.mdown

README

Zend Cache backend which stores objects inside the script's internal memory.

  • This cache backend store objects inside a Zend_Registry namespace
  • The cache objects are stored only across the script's execution
  • Memory cache can be useful in cases that your scripts calls the same function multiple times

The project requires:

  • PHP >= 5.2.1
  • Zend Framework 1.11+

Quick Example:

<?php
$frontendOptions = array(
    'automatic_serialization' => true,
    'caching' => true
);

$backendOptions = array(
);

// getting a Zend_Cache_Core object
$cache = Zend_Cache::factory('Core',
        new Application_Cache_Backend_Memory,
        $frontendOptions,
        $backendOptions);


// initially load the user (from database, memcache..)
$user = fetchUser(10);
print_R($user);

// we already loaded this user, so we won't hit the memcache / database again
$user = fetchUser(10);
print_R($user);


function fetchUser($userId)
{
    global $cache;

    $tag = 'user_' . $userId;

    // if we already loaded the user, get his object from the memory
    if (($user = $cache->load($tag)) !== false) {
        $user->from = 'this object came from the memory';
        return $user;   
    }

    // get the user data (very expensive!!)
    $user = new stdClass();
    $user->userId = $userId;
    $user->name = 'John Doe';

    $cache->save($user, $tag);

    return $user;
}
?>

Build Status