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

Source for file memcache.php

Documentation is available at memcache.php

  1. <?php
  2. /**
  3.  * File containing the ezcCacheStorageMemcache 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 class is a common base class for all Memcache based storage classes.
  30.  * To implement a Memcache based cache storage, you simply have to derive
  31.  * from this class and implement the {@link ezcCacheStorageMemcache::fetchData()}
  32.  * and {@link ezcCacheStorageMemcache::prepareData()} methods.
  33.  *
  34.  * For example code of using a cache storage, see {@link ezcCacheManager}.
  35.  *
  36.  * The Cache package already contains an implementation this class:
  37.  *  - {@link ezcCacheStorageMemcachePlain}
  38.  *
  39.  * Options for this class are defined in {@link ezcCacheStorageMemcacheOptions}.
  40.  *
  41.  * @package Cache
  42.  * @version //autogentag//
  43.  */
  44. {
  45.     /**
  46.      * The backend name.
  47.      */
  48.     const BACKEND_NAME = "Memcache";
  49.  
  50.     /**
  51.      * The registry name.
  52.      */
  53.     const REGISTRY_NAME = 'ezcCacheStorageMemcache_Registry';
  54.  
  55.     /**
  56.      * Creates a new cache storage in the given location.
  57.      *
  58.      * Options can contain the 'ttl' ( Time-To-Life ). This is per default set
  59.      * to 1 day.
  60.      *
  61.      * For details about the options see {@link ezcCacheStorageMemcacheOptions}.
  62.      *
  63.      * @throws ezcBasePropertyNotFoundException
  64.      *          If you tried to set a non-existent option value.
  65.      *
  66.      * @param string $location Path to the cache location
  67.      * @param array(string=>string) $options Options for the cache
  68.      */
  69.     public function __construct$location nullarray $options array() )
  70.     {
  71.         parent::__construct$locationarray() );
  72.  
  73.         // Overwrite parent set options with new ezcCacheMemcacheStorageOptions
  74.         $this->properties['options'new ezcCacheStorageMemcacheOptions$options );
  75.  
  76.         $this->backend = new ezcCacheMemcacheBackendarray(
  77.             'host' => $this->properties['options']->host,
  78.             'port' => $this->properties['options']->port,
  79.             'ttl' => $this->properties['options']->ttl,
  80.             'persistent' => $this->properties['options']->persistent,
  81.             'compressed' => $this->properties['options']->compressed,
  82.         ) );
  83.  
  84.         $this->registryName = self::REGISTRY_NAME;
  85.         $this->backendName = self::BACKEND_NAME;
  86.     }
  87.  
  88.     /**
  89.      * Fetches the data from the cache.
  90.      *
  91.      * @param string $identifier The memcache identifier to fetch data from
  92.      * @return mixed The fetched data or false on failure
  93.      */
  94.     abstract protected function fetchData$identifier );
  95.  
  96.     /**
  97.      * Prepare the data for storing.
  98.      *
  99.      * @throws ezcCacheInvalidDataException
  100.      *          If the data submitted can not be handled by this storage (object,
  101.      *          resource).
  102.      *
  103.      * @param mixed $data Simple type or array
  104.      * @return mixed Prepared data
  105.      */
  106.     abstract protected function prepareData$data );
  107.     
  108.     /**
  109.      * Property write access.
  110.      *
  111.      * @param string $propertyName Name of the property.
  112.      * @param mixed $val  The value for the property.
  113.      *
  114.      * @throws ezcBaseValueException
  115.      *          If the value for the property options is not an instance of
  116.      *          ezcCacheStorageOptions.
  117.      * @ignore
  118.      */
  119.     public function __set$propertyName$val )
  120.     {
  121.         switch $propertyName )
  122.         {
  123.             case 'options':
  124.                 $this->setOptions$val );
  125.                 return;
  126.             default:
  127.                 parent::__set$propertyName$val );
  128.         }
  129.     }
  130.  
  131.     /**
  132.      * Set new options.
  133.      *
  134.      * Overwrites the options with the given ones.
  135.      * 
  136.      * @param ezcCacheStorageMemcacheOptions $options The options to set.
  137.      *
  138.      * @throws ezcBasePropertyNotFoundException
  139.      *          If you tried to set a non-existent option value. The accepted
  140.      *          options depend on the ezcCacheStorage implementation and may
  141.      *          vary.
  142.      * @throws ezcBaseValueException
  143.      *          If the value is not valid for the desired option.
  144.      * @throws ezcBaseValueException
  145.      *          If you submit neither an array nor an instance of
  146.      *          ezcCacheStorageOptions.
  147.      *
  148.      * @apichange Use $storage->options instead.
  149.      */
  150.     public function setOptions$options )
  151.     {
  152.         switch true )
  153.         {
  154.             case $options instanceof ezcCacheStorageMemcacheOptions ):
  155.                 $this->properties['options'$options;
  156.                 break;
  157.             case $options instanceof ezcCacheStorageOptions ):
  158.                 $this->properties['options']->mergeStorageOptions$options );
  159.                 break;
  160.             case is_array$options ) ):
  161.                 $this->properties['options']->merge$options );
  162.                 break;
  163.             default:
  164.                 throw new ezcBaseValueException(
  165.                     'options',
  166.                     $options,
  167.                     'instance of ezcCacheStorageMemcacheOptions'
  168.                 );
  169.         }
  170.     }
  171. }
  172. ?>
Documentation generated by phpDocumentor 1.4.3