Apache Zeta Components Manual :: File Source for apc_backend.php

Source for file apc_backend.php

Documentation is available at apc_backend.php

  1. <?php
  2. /**
  3.  * File containing the ezcCacheApcBackend class.
  4.  *
  5.  * Licensed to the Apache Software Foundation (ASF) under one
  6.  * or more contributor license agreements.  See the NOTICE file
  7.  * distributed with this work for additional information
  8.  * regarding copyright ownership.  The ASF licenses this file
  9.  * to you under the Apache License, Version 2.0 (the
  10.  * "License"); you may not use this file except in compliance
  11.  * with the License.  You may obtain a copy of the License at
  12.  * 
  13.  *   http://www.apache.org/licenses/LICENSE-2.0
  14.  * 
  15.  * Unless required by applicable law or agreed to in writing,
  16.  * software distributed under the License is distributed on an
  17.  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18.  * KIND, either express or implied.  See the License for the
  19.  * specific language governing permissions and limitations
  20.  * under the License.
  21.  *
  22.  * @package Cache
  23.  * @version //autogentag//
  24.  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  25.  * @filesource
  26.  */
  27.  
  28. /**
  29.  * This backend stores data in an APC cache.
  30.  *
  31.  * @apichange This class will be deprecated in the next major version of the
  32.  *             Cache component. Please do not use it directly, but use {@link }
  33.  *             ezcCacheStorageApc} instead.
  34.  *
  35.  * @package Cache
  36.  * @version //autogentag//
  37.  */
  38. {
  39.     /**
  40.      * Constructs a new ezcCacheApcBackend object.
  41.      *
  42.      * @throws ezcBaseExtensionNotFoundException
  43.      *          If the PHP apc extension is not installed.
  44.      */
  45.     public function __construct()
  46.     {
  47.         if !ezcBaseFeatures::hasExtensionSupport'apc' ) )
  48.         {
  49.             throw new ezcBaseExtensionNotFoundException'apc'null"PHP does not have APC support." );
  50.         }
  51.     }
  52.  
  53.     /**
  54.      * Stores the data $var under the key $key. Returns true or false depending
  55.      * on the success of the operation.
  56.      *
  57.      * @param string $key 
  58.      * @param mixed $var 
  59.      * @param int $ttl 
  60.      * @return bool 
  61.      */
  62.     public function store$key$var$ttl )
  63.     {
  64.         $data new ezcCacheMemoryVarStruct$key$var$ttl );
  65.         return apc_store$key$data$ttl );
  66.     }
  67.  
  68.     /**
  69.      * Fetches the data associated with key $key.
  70.      *
  71.      * @param mixed $key 
  72.      * @return mixed 
  73.      */
  74.     public function fetch$key )
  75.     {
  76.         $data apc_fetch$key );
  77.         return is_object$data ) ) $data->var false;
  78.     }
  79.  
  80.     /**
  81.      * Deletes the data associated with key $key. Returns true or false depending
  82.      * on the success of the operation.
  83.      *
  84.      * @param string $key 
  85.      * @return bool 
  86.      */
  87.     public function delete$key )
  88.     {
  89.         return apc_delete$key );
  90.     }
  91.  
  92.     /**
  93.      * Resets the complete backend.
  94.      *
  95.      * Marked private to not expose more of this interface to the user, since
  96.      * this will be removed in future versions.
  97.      * 
  98.      * @return void 
  99.      * @access private
  100.      */
  101.     public function reset()
  102.     {
  103.         // Kills the whole user cache
  104.         apc_clear_cache"user" );
  105.     }
  106.  
  107.     /**
  108.      * Acquires a lock on the given $key.
  109.      *
  110.      * @param string $key 
  111.      * @param int $waitTime usleep()
  112.      * @param int $maxTime seconds
  113.      */
  114.     public function acquireLock$key$waitTime$maxTime )
  115.     {
  116.         $counter 0;
  117.         // add() does not replace and returns true on success. $maxTime is
  118.         // obeyed by Memcache expiry.
  119.         while apc_add$keytime()$maxTime === false )
  120.         {
  121.             // Wait for next check
  122.             usleep$waitTime );
  123.             // Don't check expiry time too frquently, since it requires restoring
  124.             if ( ( ++$counter 10 === && time(- (int)apc_fetch$key $maxTime ) )
  125.             {
  126.                 // Release expired lock and place own lock
  127.                 apc_store$keytime()$maxTime );
  128.                 break;
  129.             }
  130.         }
  131.     }
  132.  
  133.     /**
  134.      * Releases a lock on the given $key.
  135.      * 
  136.      * @param string $key 
  137.      * @return void 
  138.      */
  139.     public function releaseLock$key )
  140.     {
  141.         apc_delete$key );
  142.     }
  143. }
  144. ?>
Documentation generated by phpDocumentor 1.4.3