Elgg  Version 1.11
/root/Elgg/engine/classes/Elgg/Cache/SimpleCache.php

Get the URL for the cached fileThis automatically registers the view with Elgg's simplecache.

$blog_js = elgg_get_simplecache_url('js', 'blog/save_draft'); elgg_register_js('elgg.blog', $blog_js); elgg_load_js('elgg.blog');

Parameters
string$typeThe file type: css or js
string$viewThe view name after css/ or js/
Returns
string
<?php
namespace Elgg\Cache;
class SimpleCache {
private $CONFIG;
public function __construct() {
global $CONFIG;
$this->CONFIG = $CONFIG;
}
function registerView($view_name) {
elgg_register_external_view($view_name, true);
}
function getUrl($type, $view) {
// handle file type passed with view name
if (($type === 'js' || $type === 'css') && 0 === strpos($view, $type . '/')) {
$view = substr($view, strlen($type) + 1);
}
return _elgg_get_simplecache_root() . "$type/$view";
}
function getRoot() {
// stored in datalist as 'simplecache_lastupdate'
$lastcache = (int)_elgg_services()->config->get('lastcache');
} else {
$lastcache = 0;
}
return elgg_normalize_url("/cache/$lastcache/$viewtype/");
}
function isEnabled() {
return (bool) _elgg_services()->config->get('simplecache_enabled');
}
function enable() {
_elgg_services()->datalist->set('simplecache_enabled', 1);
_elgg_services()->config->set('simplecache_enabled', 1);
}
function disable() {
if (_elgg_services()->config->get('simplecache_enabled')) {
_elgg_services()->datalist->set('simplecache_enabled', 0);
_elgg_services()->config->set('simplecache_enabled', 0);
// purge simple cache
_elgg_rmdir(_elgg_services()->config->getDataPath() . "views_simplecache");
}
}
function invalidate() {
if (!isset($this->CONFIG->views->simplecache) || !is_array($this->CONFIG->views->simplecache)) {
return false;
}
_elgg_rmdir("{$this->CONFIG->dataroot}views_simplecache");
mkdir("{$this->CONFIG->dataroot}views_simplecache");
$time = time();
_elgg_services()->datalist->set("simplecache_lastupdate", $time);
$this->CONFIG->lastcache = $time;
return true;
}
function init() {
if (!defined('UPGRADING') && empty($this->CONFIG->lastcache)) {
$this->CONFIG->lastcache = (int)_elgg_services()->datalist->get('simplecache_lastupdate');
}
}
}
$view
Definition: crop.php:68
$type
Definition: add.php:8
_elgg_services()
Definition: autoloader.php:14
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_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
_elgg_get_simplecache_root()
Get the base url for simple cache requests.
Definition: cache.php:128
elgg_register_simplecache_view($view_name)
Registers a view to simple cache.
Definition: cache.php:98
enable()
Enables the simple cache.
init()
Set up $CONFIG appropriately on engine boot.
invalidate()
Deletes all cached views in the simplecache and sets the lastcache and lastupdate time to 0 for every...
registerView($view_name)
Registers a view to simple cache.
Definition: SimpleCache.php:47
getUrl($type, $view)
Definition: SimpleCache.php:65
getRoot()
Get the base url for simple cache requests.
Definition: SimpleCache.php:82
disable()
Disables the simple cache.
isEnabled()
Is simple cache enabled.
Definition: SimpleCache.php:99
__construct()
Constructor.
Definition: SimpleCache.php:25
$viewtype
Definition: start.php:76
elgg_normalize_url($url)
Definition: output.php:311
global $CONFIG
elgg_get_viewtype()
Return the current view type.
Definition: views.php:91
elgg_register_external_view($view, $cacheable=false)
Registers a view as being available externally (i.e.
Definition: views.php:231