Cheetah
ChWsbCacheUtilities.php
Go to the documentation of this file.
1 <?php
2 
9 {
10  protected $oMemberMenu;
11  protected $oCacheMemberMenu;
12  protected $oCachePb;
13  protected $oCacheDb;
14  protected $oCacheTemplates;
15 
16  function __construct ()
17  {
18  // member menu
19  ch_import('ChWsbMemberMenu');
20  $this->oMemberMenu = new ChWsbMemberMenu();
21  $this->oCacheMemberMenu = $this->oMemberMenu->getCacheObject();
22 
23  // page blocks
24  ch_import('ChWsbPageViewAdmin');
25  $oPageViewCacher = new ChWsbPageViewCacher ('', '');
26  $this->oCachePb = $oPageViewCacher->getBlocksCacheObject ();
27 
28  // DB
29  $this->oCacheDb = $GLOBALS['MySQL']->getDbCacheObject();
30 
31  // templates
32  $this->oCacheTemplates = $GLOBALS['oSysTemplate']->getTemplatesCacheObject();
33  }
34 
35  function clear($sCache)
36  {
37  return $this->_action($sCache, 'clear');
38  }
39 
40  function size($sCache, $isFormatted = false)
41  {
42  $iSize = $this->_action($sCache, 'size');
43  return $isFormatted ? sprintf("%.2f", $iSize / 1024 / 1024) : $iSize;
44  }
45 
46  function _action($sCache, $sMode = 'clear')
47  {
48  $sFuncCacheObject = ('clear' == $sMode ? '_clearCacheObject' : '_getSizeCacheObject');
49  $sFuncCacheFile = ('clear' == $sMode ? '_clearCache' : '_getSizeCache');
50 
51  $mixedResult = null;
52  switch ($sCache) {
53  case 'member_menu':
54  $mixedResult = $this->$sFuncCacheObject ($this->oCacheMemberMenu, $this->oMemberMenu->sMenuMemberKeysCache);
55  break;
56 
57  case 'pb':
58  $mixedResult = $this->$sFuncCacheObject ($this->oCacheDb, 'pb_');
59  break;
60 
61  case 'users':
62  $mixedResult = $this->$sFuncCacheFile('user', CH_DIRECTORY_PATH_CACHE);
63  break;
64 
65  case 'db':
66  $mixedResult = $this->$sFuncCacheObject ($this->oCacheDb, 'db_');
67  break;
68 
69  case 'template':
70  $mixedResult = $this->$sFuncCacheObject ($this->oCacheTemplates, $GLOBALS['oSysTemplate']->_sCacheFilePrefix);
71  break;
72 
73  case 'css':
74  $mixedResult = $this->$sFuncCacheFile($GLOBALS['oSysTemplate']->_sCssCachePrefix, CH_DIRECTORY_PATH_CACHE_PUBLIC);
75  break;
76 
77  case 'js':
78  $mixedResult = $this->$sFuncCacheFile($GLOBALS['oSysTemplate']->_sJsCachePrefix, CH_DIRECTORY_PATH_CACHE_PUBLIC);
79  break;
80  }
81 
82  return $mixedResult;
83  }
84 
85  function _clearCacheObject($oCache, $sPrefix)
86  {
87  if ('db_' == $sPrefix)
88  $GLOBALS['MySQL']->oParams->clearCache();
89  elseif ($this->oMemberMenu->sMenuMemberKeysCache == $sPrefix)
90  $this->oMemberMenu->deleteMemberMenuCaches();
91 
92  if (!$oCache->removeAllByPrefix ($sPrefix))
93  return array('code' => 1, 'message' => _t('_adm_txt_dashboard_cache_clean_failed'));
94  else
95  return array('code' => 0, 'message' => _t('_adm_txt_dashboard_cache_clean_success'));
96  }
97  function _getSizeCacheObject($oCache, $sPrefix)
98  {
99  return $oCache->getSizeByPrefix ($sPrefix);
100  }
101 
102  function _clearCache($sPrefix, $sPath)
103  {
104  if (!($rHandler = opendir($sPath)))
105  return array('code' => 1, 'message' => _t('_adm_txt_dashboard_cache_clean_failed'));
106 
107  $l = strlen($sPrefix);
108  while (($sFile = readdir($rHandler)) !== false)
109  if (0 === strncmp($sFile, $sPrefix, $l))
110  @unlink($sPath . $sFile);
111 
112  closedir($rHandler);
113 
114  return array('code' => 0, 'message' => _t('_adm_txt_dashboard_cache_clean_success'));
115  }
116  function _getSizeCache($sPrefix, $sPath)
117  {
118  if (!($rHandler = opendir($sPath)))
119  return 0;
120 
121  $iSize = 0;
122  $l = strlen($sPrefix);
123  while (($sFile = readdir($rHandler)) !== false)
124  if (0 === strncmp($sFile, $sPrefix, $l))
125  $iSize += filesize($sPath . $sFile);
126 
127  closedir($rHandler);
128 
129  return $iSize;
130  }
131 
132 }
ChWsbCacheUtilities\_clearCache
_clearCache($sPrefix, $sPath)
Definition: ChWsbCacheUtilities.php:102
$sMode
else $sMode
Definition: antispam.php:362
ChWsbCacheUtilities\_action
_action($sCache, $sMode='clear')
Definition: ChWsbCacheUtilities.php:46
ChWsbMemberMenu
Definition: ChWsbMemberMenu.php:92
ChWsbCacheUtilities\_getSizeCacheObject
_getSizeCacheObject($oCache, $sPrefix)
Definition: ChWsbCacheUtilities.php:97
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
php
ChWsbCacheUtilities\clear
clear($sCache)
Definition: ChWsbCacheUtilities.php:35
ChWsbCacheUtilities\size
size($sCache, $isFormatted=false)
Definition: ChWsbCacheUtilities.php:40
ChWsbCacheUtilities\$oCachePb
$oCachePb
Definition: ChWsbCacheUtilities.php:12
ChWsbCacheUtilities\$oCacheTemplates
$oCacheTemplates
Definition: ChWsbCacheUtilities.php:14
ChWsbCacheUtilities
Definition: ChWsbCacheUtilities.php:9
ChWsbPageViewCacher
Definition: ChWsbPageViewAdmin.php:944
$oCache
$oCache
Definition: prof.inc.php:10
$sFile
$sFile
Definition: index.php:20
ChWsbCacheUtilities\__construct
__construct()
Definition: ChWsbCacheUtilities.php:16
ChWsbCacheUtilities\_getSizeCache
_getSizeCache($sPrefix, $sPath)
Definition: ChWsbCacheUtilities.php:116
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
ChWsbCacheUtilities\_clearCacheObject
_clearCacheObject($oCache, $sPrefix)
Definition: ChWsbCacheUtilities.php:85
ChWsbCacheUtilities\$oCacheMemberMenu
$oCacheMemberMenu
Definition: ChWsbCacheUtilities.php:11
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10
ChWsbCacheUtilities\$oCacheDb
$oCacheDb
Definition: ChWsbCacheUtilities.php:13
ChWsbCacheUtilities\$oMemberMenu
$oMemberMenu
Definition: ChWsbCacheUtilities.php:10