Source for file zcache.inc.php

Documentation is available at zcache.inc.php

  1. <?php
  2. /**
  3. *  This file is part of the VCL for PHP project
  4. *
  5. *  Copyright (c) 2004-2008 qadram software S.L. <support@qadram.com>
  6. *
  7. *  Checkout AUTHORS file for more information on the developers
  8. *
  9. *  This library is free software; you can redistribute it and/or
  10. *  modify it under the terms of the GNU Lesser General Public
  11. *  License as published by the Free Software Foundation; either
  12. *  version 2.1 of the License, or (at your option) any later version.
  13. *
  14. *  This library is distributed in the hope that it will be useful,
  15. *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. *  Lesser General Public License for more details.
  18. *
  19. *  You should have received a copy of the GNU Lesser General Public
  20. *  License along with this library; if not, write to the Free Software
  21. *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  22. *  USA
  23. *
  24. */
  25.  
  26. require_once("vcl/vcl.inc.php");
  27. use_unit("Zend/zcommon.inc.php");
  28. use_unit("classes.inc.php");
  29. use_unit("cache.inc.php");
  30.  
  31. use_unit("Zend/framework/library/Zend/Cache.php");
  32.  
  33. define('cfCore''cfCore');
  34. define('cfOutput''cfOutput');
  35. define('cfFunction''cfFunction');
  36. define('cfClass''cfClass');
  37. define('cfFile''cfFile');
  38. define('cfPage''cfPage');
  39.  
  40. define('cbFile''cbFile');
  41. define('cbSQLite''cbSQLite');
  42. define('cbMemcached''cbMemcached');
  43. define('cbAPC''cbAPC');
  44. define('cbZendPlatform''cbPlatform');
  45.  
  46. define('rctCRC32''rctCRC32');
  47. define('rctMD5''rctMD5');
  48. define('rctADLER32''rctADLER32');
  49. define('rctSTRLEN''rctSTRLEN');
  50.  
  51. class ZCacheOptions extends Persistent
  52. {
  53.     protected $ZCache=null;
  54.  
  55.     function readOwner()
  56.     {
  57.         return($this->ZCache);
  58.     }
  59.  
  60.     function __construct($aowner)
  61.     {
  62.         parent::__construct();
  63.  
  64.         $this->ZCache=$aowner;
  65.     }
  66. }
  67.  
  68. {
  69.       protected $_cachebydefault = "1";
  70.  
  71.       function getCacheByDefault(return $this->_cachebydefault}
  72.       function setCacheByDefault($value$this->_cachebydefault = $value}
  73.       function defaultCacheByDefault(return "1"}
  74.  
  75.       protected $_cachedfunctions = array();
  76.  
  77.       function getCachedFunctions(return $this->_cachedfunctions}
  78.       function setCachedFunctions($value$this->_cachedfunctions = $value}
  79.       function defaultCachedFunctions(return array()}
  80.  
  81.       protected $_noncachedfunctions = array();
  82.  
  83.       function getNonCachedFunctions(return $this->_noncachedfunctions}
  84.       function setNonCachedFunctions($value$this->_noncachedfunctions = $value}
  85.       function defaultNonCachedFunctions(return array()}
  86. }
  87.  
  88. {
  89.     protected $_cachedentity="";
  90.  
  91.     function getCachedEntity(return $this->_cachedentity}
  92.     function setCachedEntity($value$this->_cachedentity=$value}
  93.     function defaultCachedEntity(return ""}
  94.  
  95.     protected $_cachebydefault="1";
  96.  
  97.     function getCacheByDefault(return $this->_cachebydefault}
  98.     function setCacheByDefault($value$this->_cachebydefault=$value}
  99.     function defaultCacheByDefault(return "1"}
  100.  
  101.     protected $_cachedmethods=array();
  102.  
  103.     function getCachedMethods(return $this->_cachedmethods}
  104.     function setCachedMethods($value$this->_cachedmethods=$value}
  105.     function defaultCachedMethods(return array()}
  106.  
  107.     protected $_noncachedmethods=array();
  108.  
  109.     function getNonCachedMethods(return $this->_noncachedmethods}
  110.     function setNonCachedMethods($value$this->_noncachedmethods=$value}
  111.     function defaultNonCachedMethods(return array()}
  112. }
  113.  
  114. {
  115.     protected $_masterfile="";
  116.  
  117.     function getMasterFile(return $this->_masterfile}
  118.     function setMasterFile($value$this->_masterfile=$value}
  119.     function defaultMasterFile(return ""}
  120.  
  121.  
  122. }
  123.  
  124. {
  125.     protected $_httpconditional="0";
  126.  
  127.     function getHTTPConditional(return $this->_httpconditional}
  128.     function setHTTPConditional($value$this->_httpconditional=$value}
  129.     function defaultHTTPConditional(return "0"}
  130.  
  131.     protected $_debugheader="0";
  132.  
  133.     function getDebugHeader(return $this->_debugheader}
  134.     function setDebugHeader($value$this->_debugheader=$value}
  135.     function defaultDebugHeader(return "0"}
  136.  
  137.     protected $_enabled="1";
  138.  
  139.     function getEnabled(return $this->_enabled}
  140.     function setEnabled($value$this->_enabled=$value}
  141.     function defaultEnabled(return "1"}
  142.  
  143.     protected $_cachewithget="0";
  144.  
  145.     function getCacheWithGET(return $this->_cachewithget}
  146.     function setCacheWithGET($value$this->_cachewithget=$value}
  147.     function defaultCacheWithGET(return "0"}
  148.  
  149.     protected $_cachewithpost="0";
  150.  
  151.     function getCacheWithPOST(return $this->_cachewithpost}
  152.     function setCacheWithPOST($value$this->_cachewithpost=$value}
  153.     function defaultCacheWithPOST(return "0"}
  154.  
  155.     protected $_cachewithsession="0";
  156.  
  157.     function getCacheWithSESSION(return $this->_cachewithsession}
  158.     function setCacheWithSESSION($value$this->_cachewithsession=$value}
  159.     function defaultCacheWithSESSION(return "0"}
  160.  
  161.     protected $_cachewithcookie="0";
  162.  
  163.     function getCacheWithCOOKIE(return $this->_cachewithcookie}
  164.     function setCacheWithCOOKIE($value$this->_cachewithcookie=$value}
  165.     function defaultCacheWithCOOKIE(return "0"}
  166.  
  167.     protected $_idwithget="1";
  168.  
  169.     function getIDWithGET(return $this->_idwithget}
  170.     function setIDWithGET($value$this->_idwithget=$value}
  171.     function defaultIDWithGET(return "1"}
  172.  
  173.     protected $_idwithpost="1";
  174.  
  175.     function getIDWithPOST(return $this->_idwithpost}
  176.     function setIDWithPOST($value$this->_idwithpost=$value}
  177.     function defaultIDWithPOST(return "1"}
  178.  
  179.     protected $_idwithsession="1";
  180.  
  181.     function getIDWithSESSION(return $this->_idwithsession}
  182.     function setIDWithSESSION($value$this->_idwithsession=$value}
  183.     function defaultIDWithSESSION(return "1"}
  184.  
  185.     protected $_idwithfiles="1";
  186.  
  187.     function getIDWithFiles(return $this->_idwithfiles}
  188.     function setIDWithFiles($value$this->_idwithfiles=$value}
  189.     function defaultIDWithFiles(return "1"}
  190.  
  191.     protected $_idwithcookie="1";
  192.  
  193.     function getIDWithCOOKIE(return $this->_idwithcookie}
  194.     function setIDWithCOOKIE($value$this->_idwithcookie=$value}
  195.     function defaultIDWithCOOKIE(return "1"}
  196.  
  197.  
  198.  
  199.  
  200.  
  201.     protected $_regexps=array();
  202.  
  203.     function getRegExps(return $this->_regexps}
  204.     function setRegExps($value$this->_regexps=$value}
  205.     function defaultRegExps(return array()}
  206. }
  207.  
  208. {
  209.     protected $_databasepath="";
  210.  
  211.     function getDatabasePath(return $this->_databasepath}
  212.     function setDatabasePath($value$this->_databasepath=$value}
  213.     function defaultDatabasePath(return ""}
  214.  
  215.     protected $_vacuumfactor=10;
  216.  
  217.     function getVacuumFactor(return $this->_vacuumfactor}
  218.     function setVacuumFactor($value$this->_vacuumfactor=$value}
  219.     function defaultVacuumFactor(return 10}
  220. }
  221.  
  222. {
  223.     protected $_servers=array();
  224.  
  225.     function getServers(return $this->_servers}
  226.     function setServers($value$this->_servers=$value}
  227.     function defaultServers(return array()}
  228.  
  229.     protected $_compression="0";
  230.  
  231.     function getCompression(return $this->_compression}
  232.     function setCompression($value$this->_compression=$value}
  233.     function defaultCompression(return "0"}
  234.  
  235.  
  236. }
  237.  
  238. class ZCache extends Cache
  239. {
  240.       public $zend_cache=null;
  241.  
  242.       function startCache($control$cachetype)
  243.       {
  244.           $id=$control->readNamePath().'_'.$cachetype;
  245.         $id=str_replace('.','_',$id);
  246.           return($this->start($id));
  247.       }
  248.  
  249.       function endCache()
  250.       {
  251.           $this->end();
  252.       }
  253.  
  254.       function load($id$doNotTestCacheValidity = false$doNotUnserialize = false)
  255.       {
  256.           return($this->zend_cache->load($id$doNotTestCacheValidity$doNotUnserialize));
  257.       }
  258.  
  259.       function save($data$id = null$tags = array()$specificLifetime = false)
  260.       {
  261.           return($this->zend_cache->save($data$id$tags$specificLifetime));
  262.       }
  263.  
  264.       function start($id$doNotTestCacheValidity = false)
  265.       {
  266.           return($this->zend_cache->start($id$doNotTestCacheValidity));
  267.       }
  268.  
  269.       function end($tags = array()$specificLifetime = false)
  270.       {
  271.           return($this->zend_cache->end($tags$specificLifetime));
  272.       }
  273.  
  274.       function remove($id)
  275.       {
  276.           return($this->zend_cache->remove($id));
  277.       }
  278.  
  279.       function cleanAll()
  280.       {
  281.           return($this->zend_cache->clean(Zend_Cache::CLEANING_MODE_ALL));
  282.       }
  283.  
  284.       function cleanOld()
  285.       {
  286.           return($this->zend_cache->clean(Zend_Cache::CLEANING_MODE_OLD));
  287.       }
  288.  
  289.       function cleanMatching($tags)
  290.       {
  291.           return($this->zend_cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG$tags));
  292.       }
  293.  
  294.       function cleanNotMatching($tags)
  295.       {
  296.           return($this->zend_cache->clean(Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG$tags));
  297.       }
  298.  
  299.       function call($name$parameters = array()$tags = array()$specificLifetime = false)
  300.       {
  301.           return($this->zend_cache->call($name$parameters$tags$specificLifetime));
  302.       }
  303.  
  304.  
  305.       function preinit()
  306.       {
  307.             $frontend='Output';
  308.             $backend='File';
  309.  
  310.             $frontendOptions=array();
  311.             $backendOptions=array();
  312.  
  313.             //Frontend common properties
  314.             $frontendOptions['caching']=$this->_enabled;
  315.             $frontendOptions['cache_id_prefix']=$this->_prefix;
  316.             $frontendOptions['lifetime']=$this->_lifetime;
  317.             $frontendOptions['logging']=$this->_logging;
  318.             $frontendOptions['write_control']=$this->_checkwrite;
  319.             $frontendOptions['automatic_serialization']=$this->_serialization;
  320.             $frontendOptions['automatic_cleaning_factor']=$this->_cleaningfactor;
  321.             $frontendOptions['ignore_user_abort']=$this->_ignoreuserabort;
  322.  
  323.             //Backend common properties
  324.             $backendOptions['cache_dir']=$this->_cachedir;
  325.             $backendOptions['file_locking']=$this->_filelocking;
  326.             $backendOptions['read_control']=$this->_checkread;
  327.  
  328.             //Convert read control type
  329.             $rct='crc32';
  330.             switch ($this->_readcontroltype{
  331.                 case rctCRC32:  $rct='crc32'break;
  332.                 case rctADLER32:  $rct='adler32'break;
  333.                 case rctMD5:  $rct='md5'break;
  334.                 case rctSTRLEN:  $rct='strlen'break;
  335.             }
  336.             $backendOptions['read_control_type']=$rct;
  337.             $backendOptions['hashed_directory_level']=$this->_hasheddirectorylevel;
  338.             $backendOptions['hashed_directory_umask']=$this->_hasheddirectoryumask;
  339.             $backendOptions['file_name_prefix']=$this->_filenameprefix;
  340.             $backendOptions['cache_file_umask']=$this->_cachefileumask;
  341.             $backendOptions['metadatas_array_max_size']=$this->_metadatasize;
  342.  
  343.             switch ($this->_frontend)
  344.             {
  345.                 case cfCore:
  346.                 $frontend='Core';
  347.                 break;
  348.  
  349.                 case cfOutput:
  350.                 $frontend='Output';
  351.                 break;
  352.  
  353.                 case cfFunction:
  354.                 $frontend='Function';
  355.                 break;
  356.  
  357.                 case cfClass:
  358.                 $frontend='Class';
  359.                 break;
  360.  
  361.                 case cfFile:
  362.                 $frontend='File';
  363.                 break;
  364.  
  365.                 case cfPage:
  366.                 $frontend='Page';
  367.                 break;
  368.             }
  369.  
  370.             switch ($this->_backend)
  371.             {
  372.                 case cbFile:
  373.                 $backend='File';
  374.                 break;
  375.  
  376.                 case cbSQLite:
  377.                 $backend='Sqlite';
  378.                 break;
  379.  
  380.                 case cbMemcached:
  381.                 $backend='Memcached';
  382.                 break;
  383.  
  384.                 case cbAPC:
  385.                 $backend='Apc';
  386.                 break;
  387.  
  388.                 case cbZendPlatform:
  389.                 $backend='Zend Platform';
  390.                 break;
  391.             }
  392.  
  393.             $this->zend_cache=Zend_Cache::factory($frontend$backend$frontendOptions$backendOptions);
  394.  
  395.             //Clean all cache when session is restored
  396.             if (isset($_GET['restore_session']))
  397.             {
  398.                 if (!isset($_POST['xajax']))
  399.                 {
  400.                     $this->cleanAll();
  401.                 }
  402.             }
  403.       }
  404.  
  405.       function __construct($aowner = null)
  406.       {
  407.             //Calls inherited constructor
  408.             parent::__construct($aowner);
  409.  
  410.             //Frontend properties
  411.             $this->_frontendfunctionoptions= new ZCacheFrontendFunctionOptions($this);
  412.             $this->_frontendclassoptions= new ZCacheFrontendClassOptions($this);
  413.             $this->_frontendfileoptions= new ZCacheFrontendFileOptions($this);
  414.             $this->_frontendpageoptions= new ZCacheFrontendPageOptions($this);
  415.  
  416.             //Backend properties
  417.             $this->_backendsqliteoptions=new ZCacheBackendSQLiteOptions($this);
  418.             $this->_backendmemcachedoptions=new ZCacheBackendMemcachedOptions($this);
  419.       }
  420.  
  421.       protected $_frontend = cfOutput;
  422.  
  423.       function getFrontend(return $this->_frontend}
  424.       function setFrontend($value$this->_frontend = $value}
  425.       function defaultFrontend(return cfOutput}
  426.  
  427.       protected $_backend = cbFile;
  428.  
  429.       function getBackend(return $this->_backend}
  430.       function setBackend($value$this->_backend = $value}
  431.       function defaultBackend(return cbFile}
  432.  
  433.       //Frontend properties
  434.       protected $_enabled = "1";
  435.  
  436.       function getEnabled(return $this->_enabled}
  437.       function setEnabled($value$this->_enabled = $value}
  438.       function defaultEnabled(return "1"}
  439.  
  440.       protected $_prefix = "";
  441.  
  442.       function getPrefix(return $this->_prefix}
  443.       function setPrefix($value$this->_prefix = $value}
  444.       function defaultPrefix(return ""}
  445.  
  446.       protected $_lifetime = 3600;
  447.  
  448.       function getLifetime(return $this->_lifetime}
  449.       function setLifetime($value$this->_lifetime = $value}
  450.       function defaultLifetime(return 3600}
  451.  
  452.       protected $_logging = "0";
  453.  
  454.       function getLogging(return $this->_logging}
  455.       function setLogging($value$this->_logging = $value}
  456.       function defaultLogging(return "0"}
  457.  
  458.       protected $_checkwrite = "1";
  459.  
  460.       function getCheckWrite(return $this->_checkwrite}
  461.       function setCheckWrite($value$this->_checkwrite = $value}
  462.       function defaultCheckWrite(return "1"}
  463.  
  464.       protected $_serialization = "0";
  465.  
  466.       function getSerialization(return $this->_serialization}
  467.       function setSerialization($value$this->_serialization = $value}
  468.       function defaultSerialization(return "0"}
  469.  
  470.       protected $_cleaningfactor = 10;
  471.  
  472.       function getCleaningFactor(return $this->_cleaningfactor}
  473.       function setCleaningFactor($value$this->_cleaningfactor = $value}
  474.       function defaultCleaningFactor(return 10}
  475.  
  476.       protected $_ignoreuserabort = "0";
  477.  
  478.       function getIgnoreUserAbort(return $this->_ignoreuserabort}
  479.       function setIgnoreUserAbort($value$this->_ignoreuserabort = $value}
  480.       function defaultIgnoreUserAbort(return "0"}
  481.  
  482.       //Backend properties
  483.       protected $_cachedir = '/tmp/';
  484.  
  485.       function getCacheDir(return $this->_cachedir}
  486.       function setCacheDir($value$this->_cachedir = $value}
  487.       function defaultCacheDir(return '/tmp/'}
  488.  
  489.       protected $_filelocking = "1";
  490.  
  491.       function getFileLocking(return $this->_filelocking}
  492.       function setFileLocking($value$this->_filelocking = $value}
  493.       function defaultFileLocking(return "1"}
  494.  
  495.       protected $_checkread = "1";
  496.  
  497.       function getCheckRead(return $this->_checkread}
  498.       function setCheckRead($value$this->_checkread = $value}
  499.       function defaultCheckRead(return "1"}
  500.  
  501.       protected $_readcontroltype = rctCRC32;
  502.  
  503.       function getReadControlType(return $this->_readcontroltype}
  504.       function setReadControlType($value$this->_readcontroltype = $value}
  505.       function defaultReadControlType(return rctCRC32}
  506.  
  507.       protected $_hasheddirectorylevel = 0;
  508.  
  509.       function getHashedDirectoryLevel(return $this->_hasheddirectorylevel}
  510.       function setHashedDirectoryLevel($value$this->_hasheddirectorylevel = $value}
  511.       function defaultHashedDirectoryLevel(return 0}
  512.  
  513.       protected $_hasheddirectoryumask = '700';
  514.  
  515.       function getHashedDirectoryUmask(return $this->_hasheddirectoryumask}
  516.       function setHashedDirectoryUmask($value$this->_hasheddirectoryumask = $value}
  517.       function defaultHashedDirectoryUmask(return '700'}
  518.  
  519.       protected $_filenameprefix = 'zend_cache';
  520.  
  521.       function getFileNamePrefix(return $this->_filenameprefix}
  522.       function setFileNamePrefix($value$this->_filenameprefix = $value}
  523.       function defaultFileNamePrefix(return 'zend_cache'}
  524.  
  525.       protected $_cachefileumask = '700';
  526.  
  527.       function getCacheFileUmask(return $this->_cachefileumask}
  528.       function setCacheFileUmask($value$this->_cachefileumask = $value}
  529.       function defaultCacheFileUmask(return '700'}
  530.  
  531.       protected $_metadatasize = 100;
  532.  
  533.       function getMetadataSize(return $this->_metadatasize}
  534.       function setMetadataSize($value$this->_metadatasize = $value}
  535.       function defaultMetadataSize(return 100}
  536.  
  537.       //Options for FrontEnds
  538.       protected $_frontendfunctionoptions = null;
  539.  
  540.       function getFrontendFunctionOptions(return $this->_frontendfunctionoptions}
  541.       function setFrontendFunctionOptions($value$this->_frontendfunctionoptions = $value}
  542.       function defaultFrontendFunctionOptions(return null}
  543.  
  544.     protected $_frontendclassoptions=null;
  545.  
  546.     function getFrontendClassOptions(return $this->_frontendclassoptions}
  547.     function setFrontendClassOptions($value$this->_frontendclassoptions=$value}
  548.     function defaultFrontendClassOptions(return null}
  549.  
  550.     protected $_frontendfileoptions=null;
  551.  
  552.     function getFrontendFileOptions(return $this->_frontendfileoptions}
  553.     function setFrontendFileOptions($value$this->_frontendfileoptions=$value}
  554.     function defaultFrontendFileOptions(return null}
  555.  
  556.     protected $_frontendpageoptions=null;
  557.  
  558.     function getFrontendPageOptions(return $this->_frontendpageoptions}
  559.     function setFrontendPageOptions($value$this->_frontendpageoptions=$value}
  560.     function defaultFrontendPageOptions(return null}
  561.  
  562.     protected $_backendsqliteoptions=null;
  563.  
  564.     function getBackendSQLiteOptions(return $this->_backendsqliteoptions}
  565.     function setBackendSQLiteOptions($value$this->_backendsqliteoptions=$value}
  566.     function defaultBackendSQLiteOptions(return null}
  567.  
  568.     protected $_backendmemcachedoptions=null;
  569.  
  570.     function getBackendMemcachedOptions(return $this->_backendmemcachedoptions}
  571.     function setBackendMemcachedOptions($value$this->_backendmemcachedoptions=$value}
  572.     function defaultBackendMemcachedOptions(return null}
  573.  
  574. }
  575.  
  576. ?>

Documentation generated on Fri, 26 Dec 2008 11:46:55 +0100 by phpDocumentor 1.4.0a2