Elgg  Version 1.11
SimpleCache.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg\Cache;
3 
13 class SimpleCache {
14 
20  private $CONFIG;
21 
25  public function __construct() {
26  global $CONFIG;
27  $this->CONFIG = $CONFIG;
28  }
29 
47  function registerView($view_name) {
48  elgg_register_external_view($view_name, true);
49  }
50 
65  function getUrl($type, $view) {
66  // handle file type passed with view name
67  if (($type === 'js' || $type === 'css') && 0 === strpos($view, $type . '/')) {
68  $view = substr($view, strlen($type) + 1);
69  }
70 
71  elgg_register_simplecache_view("$type/$view");
72  return _elgg_get_simplecache_root() . "$type/$view";
73  }
74 
75 
82  function getRoot() {
85  // stored in datalist as 'simplecache_lastupdate'
86  $lastcache = (int)_elgg_services()->config->get('lastcache');
87  } else {
88  $lastcache = 0;
89  }
90 
91  return elgg_normalize_url("/cache/$lastcache/$viewtype/");
92  }
93 
99  function isEnabled() {
100  return (bool) _elgg_services()->config->get('simplecache_enabled');
101  }
102 
109  function enable() {
110  _elgg_services()->datalist->set('simplecache_enabled', 1);
111  _elgg_services()->config->set('simplecache_enabled', 1);
113  }
114 
123  function disable() {
124  if (_elgg_services()->config->get('simplecache_enabled')) {
125  _elgg_services()->datalist->set('simplecache_enabled', 0);
126  _elgg_services()->config->set('simplecache_enabled', 0);
127 
128  // purge simple cache
129  _elgg_rmdir(_elgg_services()->config->getDataPath() . "views_simplecache");
130  }
131  }
132 
139  function invalidate() {
140 
141 
142  if (!isset($this->CONFIG->views->simplecache) || !is_array($this->CONFIG->views->simplecache)) {
143  return false;
144  }
145 
146  _elgg_rmdir("{$this->CONFIG->dataroot}views_simplecache");
147  mkdir("{$this->CONFIG->dataroot}views_simplecache");
148 
149  $time = time();
150  _elgg_services()->datalist->set("simplecache_lastupdate", $time);
151  $this->CONFIG->lastcache = $time;
152 
153  return true;
154  }
155 
161  function init() {
162 
163 
164  if (!defined('UPGRADING') && empty($this->CONFIG->lastcache)) {
165  $this->CONFIG->lastcache = (int)_elgg_services()->datalist->get('simplecache_lastupdate');
166  }
167  }
168 }
$view
Definition: crop.php:68
__construct()
Constructor.
Definition: SimpleCache.php:25
elgg_invalidate_simplecache()
Deletes all cached views in the simplecache and sets the lastcache and lastupdate time to 0 for every...
Definition: cache.php:220
elgg_normalize_url($url)
Definition: output.php:311
elgg_register_simplecache_view($view_name)
Registers a view to simple cache.
Definition: cache.php:98
elgg_register_external_view($view, $cacheable=false)
Registers a view as being available externally (i.e.
Definition: views.php:231
isEnabled()
Is simple cache enabled.
Definition: SimpleCache.php:99
disable()
Disables the simple cache.
getUrl($type, $view)
Definition: SimpleCache.php:65
init()
Set up $CONFIG appropriately on engine boot.
getRoot()
Get the base url for simple cache requests.
Definition: SimpleCache.php:82
invalidate()
Deletes all cached views in the simplecache and sets the lastcache and lastupdate time to 0 for every...
enable()
Enables the simple cache.
elgg_get_viewtype()
Return the current view type.
Definition: views.php:91
_elgg_services()
Definition: autoloader.php:14
registerView($view_name)
Registers a view to simple cache.
Definition: SimpleCache.php:47
elgg global
Pointer to the global context.
Definition: elgglib.js:12
_elgg_get_simplecache_root()
Get the base url for simple cache requests.
Definition: cache.php:128
$type
Definition: add.php:8
elgg_is_simplecache_enabled()
Is simple cache enabled.
Definition: cache.php:162
_elgg_rmdir($dir)
Recursively deletes a directory, including all hidden files.
Definition: cache.php:199
$viewtype
Definition: start.php:76