src/cache/ApcCache.php
public function set($key, &$value, $expires=Cache::EXPIRES_NEVER, Dependency $dependency=null) {
        if (!is_string($key))  throw new IllegalTypeException('Illegal type of parameter $key: '.gettype($key));
        if (!is_int($expires)) throw new IllegalTypeException('Illegal type of parameter $expires: '.gettype($expires));

        // data format in the cache: [created, expires, serialized([value, dependency])]
        $fullKey = $this->namespace.'::'.$key;
        $created = time();
        $data    = array($value, $dependency);

        /**
         * PHP 5.3.3/APC 3.1.3
         * -------------------
         * Bug: warning "Potential cache slam averted for key '...'"
         *      - apc_add() and apc_store() return FALSE if called multiple times for the same key
         *
         * @see http://bugs.php.net/bug.php?id=58832
         * @see http://stackoverflow.com/questions/4983370/php-apc-potential-cache-slam-averted-for-key
         *
         * - solution for APC >= 3.1.7: re-introduced setting apc.slam_defense=0
         * - no solution yet for APC 3.1.3-3.1.6
         *
         * @see http://serverfault.com/questions/342295/apc-keeps-crashing
         * @see http://stackoverflow.com/questions/1670034/why-would-apc-store-return-false
         * @see http://notmysock.org/blog/php/user-cache-timebomb.html
         */


        // store value:
        // - If possible use apc_add() which causes less memory fragmentation and minimizes lock waits.
        // - Don't use APC-TTL as the real TTL is checked in self::isCached(). APC-TTL causes various APC bugs.
        if (function_exists('apc_add')) {                                               // APC >= 3.0.13
            if (function_exists('apc_exists')) $isKey =        apc_exists($fullKey);    // APC >= 3.1.4
            else                               $isKey = (bool) apc_fetch ($fullKey);
            if ($isKey)
                apc_delete($fullKey);      // apc_delete()+apc_add() result in less memory fragmentation than apc_store()

            if (!apc_add($fullKey, array($created, $expires, serialize($data)))) {
                //Logger::log('apc_add() unexpectedly returned FALSE for $key "'.$fullKey.'" '.($isKey ? '(did exist and was deleted)':'(did not exist)'), L_WARN);
                return false;
            }
        }
        elseif (!apc_store($fullKey, array($created, $expires, serialize($data)))) {
            //Logger::log('apc_store() unexpectedly returned FALSE for $key "'.$fullKey.'" '.($isKey ? '(did exist and was deleted)':'(did not exist)'), L_WARN);
            return false;
        }

        $this->getReferencePool()->set($key, $value, $expires, $dependency);
        return true;
    }
public function set($key, &$value, $expires=Cache::EXPIRES_NEVER, Dependency $dependency=null) {
        if (!is_string($key))  throw new IllegalTypeException('Illegal type of parameter $key: '.gettype($key));
        if (!is_int($expires)) throw new IllegalTypeException('Illegal type of parameter $expires: '.gettype($expires));

        // data format in the cache: [created, expires, serialized([value, dependency])]
        $fullKey = $this->namespace.'::'.$key;
        $created = time();
        $data    = array($value, $dependency);

        /**
         * PHP 5.3.3/APC 3.1.3
         * -------------------
         * Bug: warning "Potential cache slam averted for key '...'"
         *      - apc_add() and apc_store() return FALSE if called multiple times for the same key
         *
         * @see http://bugs.php.net/bug.php?id=58832
         * @see http://stackoverflow.com/questions/4983370/php-apc-potential-cache-slam-averted-for-key
         *
         * - solution for APC >= 3.1.7: re-introduced setting apc.slam_defense=0
         * - no solution yet for APC 3.1.3-3.1.6
         *
         * @see http://serverfault.com/questions/342295/apc-keeps-crashing
         * @see http://stackoverflow.com/questions/1670034/why-would-apc-store-return-false
         * @see http://notmysock.org/blog/php/user-cache-timebomb.html
         */


        // store value:
        // - If possible use apc_add() which causes less memory fragmentation and minimizes lock waits.
        // - Don't use APC-TTL as the real TTL is checked in self::isCached(). APC-TTL causes various APC bugs.
        if (function_exists('apc_add')) {                                               // APC >= 3.0.13
            if (function_exists('apc_exists')) $isKey =        apc_exists($fullKey);    // APC >= 3.1.4
            else                               $isKey = (bool) apc_fetch ($fullKey);
            if ($isKey)
                apc_delete($fullKey);      // apc_delete()+apc_add() result in less memory fragmentation than apc_store()

            if (!apc_add($fullKey, array($created, $expires, serialize($data)))) {
                //Logger::log('apc_add() unexpectedly returned FALSE for $key "'.$fullKey.'" '.($isKey ? '(did exist and was deleted)':'(did not exist)'), L_WARN);
                return false;
            }
        }
        elseif (!apc_store($fullKey, array($created, $expires, serialize($data)))) {
            //Logger::log('apc_store() unexpectedly returned FALSE for $key "'.$fullKey.'" '.($isKey ? '(did exist and was deleted)':'(did not exist)'), L_WARN);
            return false;
        }

        $this->getReferencePool()->set($key, $value, $expires, $dependency);
        return true;
    }
public function set ( $ key , & $ value , $ expires = Cache :: EXPIRES_NEVER , Dependency $ dependency = null ) { if ( ! is_string ( $ key ) ) throw new IllegalTypeException ( 'Illegal type of parameter $key: ' . gettype ( $ key ) ) ; if ( ! is_int ( $ expires ) ) throw new IllegalTypeException ( 'Illegal type of parameter $expires: ' . gettype ( $ expires ) ) ; // data format in the cache: [created, expires, serialized([value, dependency])] $ fullKey = $ this -> namespace . '::' . $ key ; $ created = time ( ) ; $ data = array ( $ value , $ dependency ) ; /**
         * PHP 5.3.3/APC 3.1.3
         * -------------------
         * Bug: warning "Potential cache slam averted for key '...'"
         *      - apc_add() and apc_store() return FALSE if called multiple times for the same key
         *
         * @see http://bugs.php.net/bug.php?id=58832
         * @see http://stackoverflow.com/questions/4983370/php-apc-potential-cache-slam-averted-for-key
         *
         * - solution for APC >= 3.1.7: re-introduced setting apc.slam_defense=0
         * - no solution yet for APC 3.1.3-3.1.6
         *
         * @see http://serverfault.com/questions/342295/apc-keeps-crashing
         * @see http://stackoverflow.com/questions/1670034/why-would-apc-store-return-false
         * @see http://notmysock.org/blog/php/user-cache-timebomb.html
         */ // store value: // - If possible use apc_add() which causes less memory fragmentation and minimizes lock waits. // - Don't use APC-TTL as the real TTL is checked in self::isCached(). APC-TTL causes various APC bugs. if ( function_exists ( 'apc_add' ) ) { // APC >= 3.0.13 if ( function_exists ( 'apc_exists' ) ) $ isKey = apc_exists ( $ fullKey ) ; // APC >= 3.1.4 else $ isKey = ( bool ) apc_fetch ( $ fullKey ) ; if ( $ isKey ) apc_delete ( $ fullKey ) ; // apc_delete()+apc_add() result in less memory fragmentation than apc_store() if ( ! apc_add ( $ fullKey , array ( $ created , $ expires , serialize ( $ data ) ) ) ) { //Logger::log('apc_add() unexpectedly returned FALSE for $key "'.$fullKey.'" '.($isKey ? '(did exist and was deleted)':'(did not exist)'), L_WARN); return false ; } } elseif ( ! apc_store ( $ fullKey , array ( $ created , $ expires , serialize ( $ data ) ) ) ) { //Logger::log('apc_store() unexpectedly returned FALSE for $key "'.$fullKey.'" '.($isKey ? '(did exist and was deleted)':'(did not exist)'), L_WARN); return false ; } $ this -> getReferencePool ( ) -> set ( $ key , $ value , $ expires , $ dependency ) ; return true ; }
Store a value under the specified key in the cache. An existing value already stored under the key is overwritten.
If expiration time or dependency are provided and those conditions are met the value is automatically invalidated but
not automatically removed from the cache.

@param  string     $key                   - key
@param  mixed      $value                 - value
@param  int        $expires    [optional] - time in seconds after which the value becomes invalid (default: never)
@param  Dependency $dependency [optional] - a dependency object monitoring validity of the value (default: none)

@return bool - TRUE on successful storage; FALSE otherwise
Store a value under the specified key in the cache . An existing value already stored under the key is overwritten . If expiration time or dependency are provided and those conditions are met the value is automatically invalidated but not automatically removed from the cache .