XOOPS  2.6.0
functions.cache.php
Go to the documentation of this file.
1 <?php
2 
4 
17 if (!defined("FRAMEWORKS_ART_FUNCTIONS_CACHE")):
18  define("FRAMEWORKS_ART_FUNCTIONS_CACHE", true);
19 
25  {
27 
28  if (!empty($groups) && is_array($groups)) {
29  } elseif ($xoops->isUser()) {
30  $groups = $xoops->user->getGroups();
31  }
32  if (!empty($groups) && is_array($groups)) {
33  sort($groups);
34  $contentCacheId = substr(md5(implode(",", $groups) . \XoopsBaseConfig::get('db-pass') . \XoopsBaseConfig::get('db-name')), 0, strlen(\XoopsBaseConfig::get('db-user')) * 2);
35  } else {
36  $contentCacheId = FixedGroups::ANONYMOUS;
37  }
38 
39  return $contentCacheId;
40  }
41 
46  function mod_generateCacheId($groups = null)
47  {
49  }
50 
58  function mod_createFile($data, $name = null, $dirname = null, $cache_path = null)
59  {
61 
62  $name = ($name) ? $name : strval(time());
63  $dirname = ($dirname) ? $dirname : $xoops->moduleDirname;
64  $cache_path = ($cache_path) ? $cache_path : \XoopsBaseConfig::get('caches-path');
65 
66  $key = "{$dirname}_{$name}";
67  return Xoops_Cache::write($key, $data);
68  }
69 
76  function mod_createCacheFile($data, $name = null, $dirname = null)
77  {
78  return mod_createFile($data, $name, $dirname);
79  }
80 
88  function mod_createCacheFile_byGroup($data, $name = null, $dirname = null, $groups = null)
89  {
91  return mod_createCacheFile($data, $name, $dirname);
92  }
93 
100  function mod_loadFile($name, $dirname = null, $cache_path = null)
101  {
103 
104  $data = null;
105 
106  if (empty($name)) {
107  return $data;
108  }
109  $dirname = ($dirname) ? $dirname : $xoops->moduleDirname;
110  $cache_path = ($cache_path) ? $cache_path : $xoops->globalData->getVar('cache-path');
111 
112  $key = "{$dirname}_{$name}";
113  return Xoops_Cache::read($key);
114  }
115 
121  function mod_loadCacheFile($name, $dirname = null)
122  {
123  $data = mod_loadFile($name, $dirname);
124  return $data;
125  }
126 
134  {
136  $data = mod_loadFile($name, $dirname);
137  return $data;
138  }
139 
140  /* Shall we use the function of glob for better performance ? */
147  function mod_clearFile($name = "", $dirname = null, $cache_path = null)
148  {
150  if (empty($dirname)) {
151  $cache_path = ($cache_path) ? $cache_path : \XoopsBaseConfig::get('caches-path');
152  $pattern = ($dirname) ? "{$dirname}_{$name}.*\.php" : "[^_]+_{$name}.*\.php";
153  if ($handle = opendir($cache_path)) {
154  while (false !== ($file = readdir($handle))) {
155  if (is_file($cache_path . '/' . $file) && preg_match("/{$pattern}$/", $file)) {
156  @unlink($cache_path . '/' . $file);
157  }
158  }
159  closedir($handle);
160  }
161  } else {
162  $files = (array)glob($root_path . "/*{$dirname}_{$name}*.php");
163  foreach ($files as $file) {
164  @unlink($file);
165  }
166  }
167  return true;
168  }
169 
175  function mod_clearCacheFile($name = "", $dirname = null)
176  {
177  return mod_clearFile($name, $dirname);
178  }
179 
184  function mod_clearSmartyCache($pattern = "")
185  {
187 
188  if (empty($pattern)) {
189  $dirname = $xoops->moduleDirname;
190  $pattern = "/(^{$dirname}\^.*\.html$|blk_{$dirname}_.*[^\.]*\.html$)/";
191  }
192  $cache_path = $xoops->globalData->getVar('cache-path');
193  if ($handle = opendir($cache_path)) {
194  while (false !== ($file = readdir($handle))) {
195  if (is_file($cache_path . '/' . $file) && preg_match($pattern, $file)) {
196  @unlink($cache_path . '/' . $file);
197  }
198  }
199  closedir($handle);
200  }
201  return true;
202  }
203 
205 ?>
mod_clearSmartyCache($pattern="")
mod_clearCacheFile($name="", $dirname=null)
mod_loadCacheFile_byGroup($name, $dirname=null, $groups=null)
static getInstance()
Definition: Xoops.php:160
if(!isset($xoops->paths[$path_type])) if($path_type== 'var') $file
Definition: browse.php:55
mod_createFile($data, $name=null, $dirname=null, $cache_path=null)
$files
Definition: index.php:35
mod_createCacheFile($data, $name=null, $dirname=null)
static read($key)
Definition: Legacy.php:94
mod_loadCacheFile($name, $dirname=null)
$xoops
Definition: admin.php:25
static get($name)
mod_generateCacheId_byGroup($groups=null)
$groups
mod_generateCacheId($groups=null)
static write($key, $value, $duration=0)
Definition: Legacy.php:76
$dirname
Definition: backend.php:38
mod_createCacheFile_byGroup($data, $name=null, $dirname=null, $groups=null)
mod_clearFile($name="", $dirname=null, $cache_path=null)
mod_loadFile($name, $dirname=null, $cache_path=null)