We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Cache APC - prefix error

I created 2 project on the same server.

Project-1:

    $frontCache = new \Phalcon\Cache\Frontend\Data(array(
            "lifetime" => 86400
    ));
    $cache = new \Phalcon\Cache\Backend\Apc($frontCache, array(
            'prefix' => 'prefix-1-'
    ));

Project-2:

    $frontCache = new \Phalcon\Cache\Frontend\Data(array(
            "lifetime" => 86400
    ));
    $cache = new \Phalcon\Cache\Backend\Apc($frontCache, array(
            'prefix' => 'prefix-2-'
    ));

Both Project-1 and Project-2 save a cached object the same key but with different value.

When I open both projects the cached object have the same value. It seems that APC use no prefix.

Thanks for the help!

edited May '16

        var prefix;

        /**
         * A common option is the prefix
         */
        if fetch prefix, options["prefix"] {
            let this->_prefix = prefix;
        }

it should respect prefix since keys are stored globally as _PHCAyour-app-prefixActualkeyName

/**
     * Returns a cached content
     *
     * @param   string|long keyName
     * @param   long lifetime
     * @return  mixed
     */
    public function get(string! keyName, var lifetime = null)
    {
        var prefixedKey, cachedContent;

        let prefixedKey = "_PHCA" . this->_prefix . keyName,
            this->_lastKey = prefixedKey;

        let cachedContent = apc_fetch(prefixedKey);
        if cachedContent === false {
            return null;
        }

        return this->_frontend->afterRetrieve(cachedContent);
    }

In any case, I'd recommend you to use (lib)Memcached instead of APCU. https://docs.phalcon.io/en/latest/api/Phalcon_Cache_Backend_Libmemcached.html

01010000011010000110000101101100011000110110111101101110010100000100100001010000