Search code examples
zend-frameworkzend-cache

What are different between Backend vs Frontend Cache of Zend Framework


I am implementing caching for my website which is using Zend Framework.

I look into the source code and see that:

Zend_Cache::factory()

always need two configurations of backend and frontend.

And my issue is:

I don't know why backend is set inside frontend,
and what is the difference between them?

$frontendObject->setBackend($backendObject);
return $frontendObject;

Here is the orginal source code:

public static function factory($frontend, $backend, $frontendOptions = array(), $backendOptions = array(), $customFrontendNaming = false, $customBackendNaming = false, $autoload = false)
{
    if (is_string($backend)) {
        $backendObject = self::_makeBackend($backend, $backendOptions, $customBackendNaming, $autoload);
    } else {
        if ((is_object($backend)) && (in_array('Zend_Cache_Backend_Interface', class_implements($backend)))) {
            $backendObject = $backend;
        } else {
            self::throwException('backend must be a backend name (string) or an object which implements Zend_Cache_Backend_Interface');
        }
    }
    if (is_string($frontend)) {
        $frontendObject = self::_makeFrontend($frontend, $frontendOptions, $customFrontendNaming, $autoload);
    } else {
        if (is_object($frontend)) {
            $frontendObject = $frontend;
        } else {
            self::throwException('frontend must be a frontend name (string) or an object');
        }
    }
    $frontendObject->setBackend($backendObject);
    return $frontendObject;
}

Solution

  • The cache backend is the "cache engine" : it can be file, memcached, etc.

    The cache frontend specify what kind of data will be stored in the cache (see http://framework.zend.com/manual/1.12/en/zend.cache.frontends.html)