web/Zend/Cache/Backend/BlackHole.php
changeset 0 4eba9c11703f
equal deleted inserted replaced
-1:000000000000 0:4eba9c11703f
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_Cache
       
    17  * @subpackage Zend_Cache_Backend
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: BlackHole.php 20785 2010-01-31 09:43:03Z mikaelkael $
       
    21  */
       
    22 
       
    23 /**
       
    24  * @see Zend_Cache_Backend_Interface
       
    25  */
       
    26 require_once 'Zend/Cache/Backend/ExtendedInterface.php';
       
    27 
       
    28 /**
       
    29  * @see Zend_Cache_Backend
       
    30  */
       
    31 require_once 'Zend/Cache/Backend.php';
       
    32 
       
    33 /**
       
    34  * @package    Zend_Cache
       
    35  * @subpackage Zend_Cache_Backend
       
    36  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    37  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    38  */
       
    39 class Zend_Cache_Backend_BlackHole 
       
    40     extends Zend_Cache_Backend 
       
    41     implements Zend_Cache_Backend_ExtendedInterface
       
    42 {
       
    43     /**
       
    44      * Test if a cache is available for the given id and (if yes) return it (false else)
       
    45      *
       
    46      * @param  string $id cache id
       
    47      * @param  boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested
       
    48      * @return string|false cached datas
       
    49      */
       
    50     public function load($id, $doNotTestCacheValidity = false)
       
    51     {
       
    52         return false;
       
    53     }
       
    54 
       
    55     /**
       
    56      * Test if a cache is available or not (for the given id)
       
    57      *
       
    58      * @param  string $id cache id
       
    59      * @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
       
    60      */
       
    61     public function test($id)
       
    62     {
       
    63         return false;
       
    64     }
       
    65 
       
    66     /**
       
    67      * Save some string datas into a cache record
       
    68      *
       
    69      * Note : $data is always "string" (serialization is done by the
       
    70      * core not by the backend)
       
    71      *
       
    72      * @param  string $data             Datas to cache
       
    73      * @param  string $id               Cache id
       
    74      * @param  array  $tags             Array of strings, the cache record will be tagged by each string entry
       
    75      * @param  int    $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
       
    76      * @return boolean true if no problem
       
    77      */
       
    78     public function save($data, $id, $tags = array(), $specificLifetime = false)
       
    79     {
       
    80         return true;
       
    81     }
       
    82 
       
    83     /**
       
    84      * Remove a cache record
       
    85      *
       
    86      * @param  string $id cache id
       
    87      * @return boolean true if no problem
       
    88      */
       
    89     public function remove($id)
       
    90     {
       
    91         return true;
       
    92     }
       
    93 
       
    94     /**
       
    95      * Clean some cache records
       
    96      *
       
    97      * Available modes are :
       
    98      * 'all' (default)  => remove all cache entries ($tags is not used)
       
    99      * 'old'            => remove too old cache entries ($tags is not used)
       
   100      * 'matchingTag'    => remove cache entries matching all given tags
       
   101      *                     ($tags can be an array of strings or a single string)
       
   102      * 'notMatchingTag' => remove cache entries not matching one of the given tags
       
   103      *                     ($tags can be an array of strings or a single string)
       
   104      * 'matchingAnyTag' => remove cache entries matching any given tags
       
   105      *                     ($tags can be an array of strings or a single string)
       
   106      *
       
   107      * @param  string $mode clean mode
       
   108      * @param  tags array $tags array of tags
       
   109      * @return boolean true if no problem
       
   110      */
       
   111     public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
       
   112     {
       
   113         return true;
       
   114     }
       
   115 
       
   116     /**
       
   117      * Return an array of stored cache ids
       
   118      *
       
   119      * @return array array of stored cache ids (string)
       
   120      */
       
   121     public function getIds()
       
   122     {
       
   123         return array();
       
   124     }
       
   125 
       
   126     /**
       
   127      * Return an array of stored tags
       
   128      *
       
   129      * @return array array of stored tags (string)
       
   130      */
       
   131     public function getTags()
       
   132     {
       
   133         return array();
       
   134     }
       
   135 
       
   136     /**
       
   137      * Return an array of stored cache ids which match given tags
       
   138      *
       
   139      * In case of multiple tags, a logical AND is made between tags
       
   140      *
       
   141      * @param array $tags array of tags
       
   142      * @return array array of matching cache ids (string)
       
   143      */
       
   144     public function getIdsMatchingTags($tags = array())
       
   145     {
       
   146         return array();
       
   147     }
       
   148 
       
   149     /**
       
   150      * Return an array of stored cache ids which don't match given tags
       
   151      *
       
   152      * In case of multiple tags, a logical OR is made between tags
       
   153      *
       
   154      * @param array $tags array of tags
       
   155      * @return array array of not matching cache ids (string)
       
   156      */
       
   157     public function getIdsNotMatchingTags($tags = array())
       
   158     {
       
   159         return array();
       
   160     }
       
   161 
       
   162     /**
       
   163      * Return an array of stored cache ids which match any given tags
       
   164      *
       
   165      * In case of multiple tags, a logical AND is made between tags
       
   166      *
       
   167      * @param  array $tags array of tags
       
   168      * @return array array of any matching cache ids (string)
       
   169      */
       
   170     public function getIdsMatchingAnyTags($tags = array())
       
   171     {
       
   172         return array();
       
   173     }
       
   174 
       
   175     /**
       
   176      * Return the filling percentage of the backend storage
       
   177      *
       
   178      * @return int integer between 0 and 100
       
   179      * @throws Zend_Cache_Exception
       
   180      */
       
   181     public function getFillingPercentage()
       
   182     {
       
   183         return 0;
       
   184     }
       
   185 
       
   186     /**
       
   187      * Return an array of metadatas for the given cache id
       
   188      *
       
   189      * The array must include these keys :
       
   190      * - expire : the expire timestamp
       
   191      * - tags : a string array of tags
       
   192      * - mtime : timestamp of last modification time
       
   193      *
       
   194      * @param  string $id cache id
       
   195      * @return array array of metadatas (false if the cache id is not found)
       
   196      */
       
   197     public function getMetadatas($id)
       
   198     {
       
   199         return false;
       
   200     }
       
   201 
       
   202     /**
       
   203      * Give (if possible) an extra lifetime to the given cache id
       
   204      *
       
   205      * @param  string $id cache id
       
   206      * @param  int $extraLifetime
       
   207      * @return boolean true if ok
       
   208      */
       
   209     public function touch($id, $extraLifetime)
       
   210     {
       
   211         return false;
       
   212     }
       
   213 
       
   214     /**
       
   215      * Return an associative array of capabilities (booleans) of the backend
       
   216      *
       
   217      * The array must include these keys :
       
   218      * - automatic_cleaning (is automating cleaning necessary)
       
   219      * - tags (are tags supported)
       
   220      * - expired_read (is it possible to read expired cache records
       
   221      *                 (for doNotTestCacheValidity option for example))
       
   222      * - priority does the backend deal with priority when saving
       
   223      * - infinite_lifetime (is infinite lifetime can work with this backend)
       
   224      * - get_list (is it possible to get the list of cache ids and the complete list of tags)
       
   225      *
       
   226      * @return array associative of with capabilities
       
   227      */
       
   228     public function getCapabilities()
       
   229     {
       
   230         return array(
       
   231             'automatic_cleaning' => true,
       
   232             'tags'               => true,
       
   233             'expired_read'       => true,
       
   234             'priority'           => true,
       
   235             'infinite_lifetime'  => true,
       
   236             'get_list'           => true,
       
   237         );
       
   238     }
       
   239 
       
   240     /**
       
   241      * PUBLIC METHOD FOR UNIT TESTING ONLY !
       
   242      *
       
   243      * Force a cache record to expire
       
   244      *
       
   245      * @param string $id cache id
       
   246      */
       
   247     public function ___expire($id)
       
   248     {
       
   249     }
       
   250 }